#include using namespace std; template struct SuffixArray { int N, K; vector sa, rank, tmp; SuffixArray(int n, T &s) : N(n) { sa.resize(N+1); rank.resize(N+1); tmp.resize(N+1); for (int i = 0; i <= N; i++) { sa[i] = i; rank[i] = i < N ? s[i] : -1; } auto compare = [&] (int i, int j) { if (rank[i] != rank[j]) return rank[i] < rank[j]; else { int ri = i + K <= N ? rank[i + K] : -1; int rj = j + K <= N ? rank[j + K] : -1; return ri < rj; } }; for (K = 1; K <= N; K <<= 1) { sort(sa.begin(), sa.end(), compare); tmp[sa[0]] = 0; for (int i = 1; i <= n; i++) { tmp[sa[i]] = tmp[sa[i-1]] + (compare(sa[i-1], sa[i])); } for (int i = 0; i <= n; i++) { rank[i] = tmp[i]; } } } // return index of i-th suffix int operator[] (const int &i) const { return sa[i+1]; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); long long n, m, q; cin >> n >> m >> q; string s; cin >> s; auto cut = [&](int x) { bool ok = true; for (int i = 0; i < n-x && ok; i++) { if (s[i] == s[i+x]) continue; ok = false; } return ok; }; long long t = n; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { if (cut(i)) t = min(i, t); if (cut(n/i)) t = min(n/i, t); } } s = s.substr(0, t); m *= n / t; n = t; string u = s + s; SuffixArray sf(n*2, u); long long curr = 0; int i = 0; vector ans(q); for (int qi = 0; qi < q; qi++) { long long k; cin >> k; while (curr < k) { auto x = sf[i] + 1; //cout << qi << " " << curr << " " << k << " " << x << "\n"; if (x > n) { if (curr + 1 < k) { curr++, i++; continue; } else if (curr + 1 == k) { ans[qi] = (m-1) * n + (x-n); break; } } else { if (curr + (m-1) < k) { curr += m-1, i++; } else { auto y = k - curr; ans[qi] = (m-y-1) * n + x; break; } } } } for (int i = 0; i < q; i++) { if (i) cout << " "; cout << ans[i]; } cout << "\n"; return 0; }