// clang-format off
#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
mt19937 gen(time(0));
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii; typedef pair<ll,int> pli; typedef pair<ll,ll> pll; typedef pair<int,ll> pil;
inline ll read(){
ll x=0,f=1,c=getchar();
while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
const int N=5e5+3;
const int bs=26;
// clang-format on
inline int fp(int x,int p,int m){
int res=1;
for(;p;p>>=1){
if(p&1)res=1ll*res*x%m;
x=1ll*x*x%m;
}
return res;
}
const int mod1=998244353,mod2=167772161,mod3=1004535809;
struct Int{
int x,y,z;
Int(int a=0,int b=0,int c=0){x=a,y=b,z=c;}
//Int(Int A){x=A.x,y=A.y,z=A.z;}
};
Int B(bs,bs,bs);
Int operator +(Int a,Int b){return Int((a.x+b.x)%mod1,(a.y+b.y)%mod2,(a.z+b.z)%mod3);}
Int operator -(Int a,Int b){return Int((a.x-b.x+mod1)%mod1,(a.y-b.y+mod2)%mod2,(a.z-b.z+mod3)%mod3);}
Int operator *(Int a,Int b){return Int(1ll*a.x*b.x%mod1,1ll*a.y*b.y%mod2,1ll*a.z*b.z%mod3);}
bool operator == (Int a,Int b){return a.x==b.x && a.y==b.y && a.z==b.z;}
Int p[N],h[N];
int n,m,a[N],lp[N],rp[N],s[N];
struct Node{int l,r,id;};
inline bool check(int k,int len){
if(k==len)return 1;
int l=lp[k],r=rp[k]-len;
Int res1 = h[r] - (h[l-1]*p[r-l+1]);
l=lp[k]+len,r=rp[k];
Int res2 = h[r] - (h[l-1]*p[r-l+1]);
return res1 == res2;
}
const int M=1<<19;
int t[M<<1];
inline void update(int x,int k){
t[x+=M]=k;
for(x>>=1;x;x>>=1)t[x]=min(t[x<<1],t[x<<1|1]);
}
inline int query(int l,int r){
int res=INT_MAX;
for(l+=M-1,r+=M+1;l^r^1;l>>=1,r>>=1){
if(~l&1)res=min(res,t[l^1]);
if(r&1) res=min(res,t[r^1]);
}
return res;
}
vector<Node>que[N];
vector<pii>op[N];
int main() {
//freopen("data.in", "r", stdin);
// freopen(".in","r",stdin);
// freopen("myans.out","w",stdout);
p[0]=Int(1,1,1);rep(i,1,N-1)p[i]=p[i-1]*B;
n=read();
static char tmp[N];scanf("%s",tmp+1);
int l=1,r=0;
deque<int>dq;
rep(i,1,n){
if(tmp[i]>='a' && tmp[i]<='z'){ dq.push_front(tmp[i]-'a'+1); --l; }
else{ dq.push_back(tmp[i]-'A'+1); ++r; }
lp[i]=l,rp[i]=r;
}
rep(i,1,n)s[i]=dq[i-1],lp[i]-=l-1,rp[i]-=l-1,h[i]=Int(s[i],s[i],s[i]) + h[i-1]*B;
m=read();
rep(i,1,m){
a[i]=read();
int l=a[i],r=n;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid,a[i]))l=mid+1;
else r=mid-1;
}
op[r].pb(P(i,a[i]));
op[a[i]-1].pb(P(i,INT_MAX));
}
int q=read();
rep(i,1,q){
int k=read(),l=read(),r=read();
que[k].pb({l,r,i});
}
memset(t,0x7f,sizeof t);
static int ans[N];
per(k,n,1){
for(auto tmp:op[k])update(tmp.fi,tmp.se);
for(auto tmp:que[k])ans[tmp.id]=query(tmp.l,tmp.r);
}
rep(i,1,q)printf("%d\n",ans[i]>n?-1:ans[i]);
return 0;
}