#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; constexpr int inf=1e9+7; constexpr ll longinf=1LL<<60 ; constexpr ll mod=1e9+7 ; struct SuffixArray { vector< int > SA; const string s; SuffixArray(const string &str) : s(str) { SA.resize(s.size()); iota(begin(SA), end(SA), 0); sort(begin(SA), end(SA), [&](int a, int b) { return s[a] == s[b] ? a > b : s[a] < s[b]; }); vector< int > classes(s.size()), c(s.begin(), s.end()), cnt(s.size()); for(int len = 1; len < s.size(); len <<= 1) { for(int i = 0; i < s.size(); i++) { if(i > 0 && c[SA[i - 1]] == c[SA[i]] && SA[i - 1] + len < s.size() && c[SA[i - 1] + len / 2] == c[SA[i] + len / 2]) { classes[SA[i]] = classes[SA[i - 1]]; } else { classes[SA[i]] = i; } } iota(begin(cnt), end(cnt), 0); copy(begin(SA), end(SA), begin(c)); for(int i = 0; i < s.size(); i++) { int s1 = c[i] - len; if(s1 >= 0) SA[cnt[classes[s1]]++] = s1; } classes.swap(c); } } int operator[](int k) const { return SA[k]; } size_t size() const { return s.size(); } bool lt_substr(const string &t, int si = 0, int ti = 0) { int sn = (int) s.size(), tn = (int) t.size(); while(si < sn && ti < tn) { if(s[si] < t[ti]) return true; if(s[si] > t[ti]) return false; ++si, ++ti; } return si >= sn && ti < tn; } int lower_bound(const string &t) { int low = -1, high = (int) SA.size(); while(high - low > 1) { int mid = (low + high) / 2; if(lt_substr(t, SA[mid])) low = mid; else high = mid; } return high; } pair< int, int > lower_upper_bound(string &t) { int idx = lower_bound(t); int low = idx - 1, high = (int) SA.size(); t.back()++; while(high - low > 1) { int mid = (low + high) / 2; if(lt_substr(t, SA[mid])) low = mid; else high = mid; } t.back()--; return {idx, high}; } void output() { for(int i = 0; i < size(); i++) { cout << i << ": " << s.substr(SA[i]) << endl; } } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n,k,q; cin>>n>>k>>q; string S; cin>>S; vector A(n); A[0] = S.size(); int i = 1, j = 0; while (i < S.size()) { while (i+j < S.size() && S[j] == S[i+j]) ++j; A[i] = j; if (j == 0) { ++i; continue;} int k = 1; while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k; i += k; j -= k; } REP(i,1,n){ if(A[i]==n-i && n%i==0){ k*=n/i; n=i; S.resize(i); break; } } if(k>=2)S = S + S; SuffixArray sa(S); int cur = 0; ll sum = 0; vector ans(q); rep(i,q){ ll t; cin>>t; while(1){ ll x = sa[cur]>=n?1:k-1; if(t<=sum+x)break; sum += x; ++cur; } if(sa[cur]