#include<bits/stdc++.h>
using namespace std;
constexpr int N=5e5+5;
int n,m,q,L[N],R[N],ans[N],t[N<<2];
vector<int> Q[N],P[N],E[N];
constexpr int inf=1e9;
#define ls p<<1
#define rs p<<1|1
inline void U(int p){t[p]=min(t[ls],t[rs]);}
void B(int p,int l,int r){
t[p]=inf;
if(l==r) return;
int mid=l+r>>1;
B(ls,l,mid),B(rs,mid+1,r);
}
void M(int p,int l,int r,int k,int x){
if(l==r) return t[p]=x,void();
int mid=l+r>>1;
if(k<=mid) M(ls,l,mid,k,x);
else M(rs,mid+1,r,k,x);
U(p);
}
int Y(int p,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr) return t[p];
int mid=l+r>>1,res=inf;
if(ql<=mid) res=Y(ls,l,mid,ql,qr);
if(qr>mid) res=min(res,Y(rs,mid+1,r,ql,qr));
return res;
}
typedef unsigned long long Z;
constexpr Z mod=998244853;
const Z bas=random_device{}()%1000000+2000;
Z bs[N],hsh[N];
inline Z G(int l,int r){
return (hsh[r]+mod-hsh[l-1]*bs[r-l+1]%mod)%mod;
}
string s,r,rv;int dt[maxn];
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>s>>m;for(int i=bs[0]=1;i<=n;i++) bs[i]=bs[i-1]*bas%mod;
for(int i=1,x;i<=m;i++) cin>>x,P[x].push_back(i);cin>>q;
for(int i=1,x;i<=q;i++) cin>>x>>L[i]>>R[i],Q[x].push_back(i);
for(int i=1;i<n;i++) if(s[i]>='a'&&s[i]<='z') dt[1]++;
for(int i=1;i<n;i++) dt[i+1]=dt[i]-(s[i]>='a'&&s[i]<='z');
for(auto x:s) if(x>='a'&&x<='z') rv+=x;else r+=x+'a'-'A';
reverse(rv.begin(),rv.end());r=rv+r;
for(int i=0;i<n;i++) hsh[i+1]=(hsh[i]*bas+r[i])%mod;
for(int i=1;i<=n;i++){
int l=i,r=n;
while(l<r){
int mid=l+r+1>>1,d=dt[mid],L=mid-i;
if(G(d+1,d+L)==G(d+mid-L+1,d+mid)) l=mid;
else r=mid-1;
}E[l+1].push_back(i);
}B(1,1,m);
for(int i=1;i<=n;i++){
for(auto x:P[i]) M(1,1,m,x,i);
for(auto x:E[i])for(auto y:P[x]) M(1,1,m,y,inf);
for(auto x:Q[i]) ans[x]=Y(1,1,m,L[x],R[x]);
}
for(int i=1;i<=q;i++) cout<<(ans[i]==inf?-1:ans[i])<<'\n';
}