#include using namespace std; using P = pair; const int M = 1000000007; class suffix_array { // compare (rank[i], rank[i + k]) and (rank[j], rank[j + k]) static bool compare_sa(int n, const vector& rank, int i, int j, int k) { if (rank[i] != rank[j]) return rank[i] < rank[j]; int ri = i + k <= n ? rank[i + k] : -1; int rj = j + k <= n ? rank[j + k] : -1; return ri < rj; } public: static vector construct_sa(const string& s) { int n = s.size(); vector sa(n + 1), rank(n + 1); for (int i = 0; i <= n; ++i) { sa[i] = i; rank[i] = i < n ? s[i] : -1; } for (int k = 1; k <= n; k <<= 1) { sort(sa.begin(), sa.end(), [&n, &k, &rank](const int& a, const int& b){ return compare_sa(n, rank, a, b, k); }); vector tmp(n + 1); for (int i = 1; i <= n; ++i) tmp[sa[i]] = tmp[sa[i - 1]] + compare_sa(n, rank, sa[i - 1], sa[i], k); for (int i = 0; i <= n; ++i) rank[i] = tmp[i]; } return sa; } static vector construct_lcp(const string& s, const vector& sa) { int n = s.length(); vector rank(n + 1), lcp(n + 1); for (int i = 0; i <= n; ++i) rank[sa[i]] = i; int h = 0; for (int i = 0; i < n; ++i) { if (h > 0) --h; for (int j = sa[rank[i] - 1]; j + h < n && i + h < n; ++h) if (s[j + h] != s[i + h]) break; lcp[rank[i] - 1] = h; } return lcp; } }; class segtree { private: int n, s, t; vector tr; const int ex = M; int q(int k, int l, int r) { return r <= s || t <= l ? ex : s <= l && r <= t ? tr[k] : min(q(k << 1 | 1, l, (l + r) >> 1), q((k + 1) << 1, (l + r) >> 1, r)); } public: segtree(int m) { n = 1; while (n < m) n <<= 1; tr.clear(); tr.resize((n << 1) - 1, ex); } void update(int j, const int& x) { int i = j + n - 1; tr[i] = x; while (i > 0) { i = (i - 1) >> 1; tr[i] = min(tr[i << 1 | 1], tr[(i + 1) << 1]); } } // [s, t) int run(int _s, int _t) { s = _s; t = _t; return q(0, 0, n); } }; vector kmp(const string& s) { int n = s.length(); vector res(n + 1); res[0] = -1; int j = -1; for (int i = 0; i < n; ++i) { while (j >= 0 && s[i] != s[j]) j = res[j]; j++; res[i + 1] = j; } return res; } vector solve(const string& s, long long m, const vector& qs) { int n = s.length(); int q = qs.size(); int l = n - kmp(s)[n]; if (l > 0 && l < n && n % l == 0) { return solve(s.substr(0, l), m * n / l, qs); } vector res(q); if (m == 1) { vector sa = suffix_array::construct_sa(s); for (int i = 0; i < q; ++i) { res[i] = sa[qs[i]] + 1; } } else { string t = s + s; vector sa = suffix_array::construct_sa(t); long long cnt = 0; int qi = 0; for (int i = 1; i <= n * 2; ++i) { if (sa[i] >= n) { if (qi < q && cnt + 1 == qs[qi]) { res[qi] = (m - 2) * n + sa[i] + 1; ++qi; } ++cnt; } else { while (qi < q && cnt + m - 1 >= qs[qi]) { res[qi] = (m - (qs[qi] - cnt + 1)) * n + sa[i] + 1; ++qi; } cnt += m - 1; } } } return res; } int main() { cin.tie(0); ios::sync_with_stdio(0); int n, q; long long m; string s; cin >> n >> m >> q >> s; vector qs(q); for (int i = 0; i < q; ++i) { cin >> qs[i]; } vector res = solve(s, m, qs); for (int i = 0; i < q; ++i) { cout << res[i] << (i < q - 1 ? ' ' : '\n'); } return 0; }