#include #include #include using namespace std; typedef long long ll; typedef pair P; typedef pair P1; typedef pair P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i,x) for(int i=0;i> n >> k >> q; cin >> ss; rep(i,5) s += ss; num[0][0] = num[0][1] = 1; rep(i,1000003){ num[i+1][0] = num[i][0]*31LL%mod; num[i+1][1] = num[i][1]*37LL%mod; } rep(i,s.size()){ rep(j,2){ if(i) h[i][j] = h[i-1][j]; h[i][j] += num[i][j]*(s[i]-'a'+1)%mod; if(h[i][j]>=mod) h[i][j]-=mod; } } for(int i=s.size()-1;i>=0;i--){ rep(j,2){ r[i][j] = r[i+1][j]; r[i][j] += num[s.size()-1-i][j]*(s[i]-'a'+1)%mod; if(r[i][j]>=mod) r[i][j]-=mod; } } rep(i,q){ ll a; scanf("%lld",&a); ll mn = min(a-1,1LL*k*n-a); int pos = (a-1)%(ss.size()); int p = ss.size()*2+pos; int lb = 0, ub = n+1; while(ub-lb > 1){ int mid = (lb+ub)/2; //[p-mid,p-1] //[p+1,p+mid] rep(j,2){ //x^(p+1) ll vr = h[p+mid][j]-h[p][j]; vr = vr*num[s.size()-p-1][j]%mod; //x^(s.size()-p) ll vl = r[p-mid][j]-r[p][j]; vl = vl*num[p][j]%mod; if(vr < 0) vr+=mod; if(vl < 0) vl+=mod; if(vl != vr) goto fail; } lb = mid; continue; fail:; ub = mid; } if(lb != n){ printf("%lld\n",min(1LL*lb,mn)*2LL+1); } else{ printf("%lld\n",mn*2LL+1); } } }