#include using namespace std; struct RollingHash { static constexpr long long m31 = (1LL << 31) - 1; static int mod_m31(long long a) { a = (a >> 31) + (a & m31); return a >= m31 ? a - m31 : a; } static long long base[2]; static vector powb[2]; vector h[2]; RollingHash(const string& s) : h{{0}, {0}} { for (int k : {0, 1}) { for (char c : s) h[k].push_back(mod_m31(h[k].back() * base[k] + c)); while (powb[k].size() <= s.size()) powb[k].push_back(mod_m31(powb[k].back() * base[k])); } } int get(int l, int r, int k) const { return mod_m31(h[k][r] + (m31 - h[k][l]) * powb[k][r - l]); } auto get(int l, int r) const { return make_pair(get(l, r, 0), get(l, r, 1)); } static long long powerb(long long n, int k) { long long res = 1, t = base[k]; while (n) { if (n & 1) { res = mod_m31(res * t); } t = mod_m31(t * t); n >>= 1; } return res; } static int merge(long long hl, long long hr, long long len, int k) { return mod_m31(hl * powerb(len, k) + hr); } static auto merge(pair hl, pair hr, long long len) { return make_pair(merge(hl.first, hr.first, len, 0), merge(hl.second, hr.second, len, 1)); } }; long long RollingHash::base[2] = {1095803926, 1410736294}; vector RollingHash::powb[2] = {{1}, {1}}; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); long long n, k, q; cin >> n >> k >> q; string s; cin >> s; RollingHash rh(s + s); reverse(begin(s), end(s)); RollingHash rev(s + s); auto pw = [&](auto h, long long num) { auto res = make_pair(0, 0); long long len = n; while (num) { if (num & 1) { res = rh.merge(res, h, len); } h = rh.merge(h, h, len); len *= 2; num >>= 1; } return res; }; while (q--) { long long a; cin >> a; --a; auto f = [&](const auto& rh, long long l, long long r) { if (r - l <= n) { return rh.get(l % n, l % n + (r - l)); } auto x = rh.get(l % n, n); l = (l + n - 1) / n * n; auto z = rh.get(0, r % n); int zl = r % n; r = r / n * n; auto y = pw(rh.get(0, n), (r - l) / n); return rh.merge(rh.merge(x, y, r - l), z, zl); }; long long ok = 1, ng = min(a + 1, k * n - a) + 1; while (ng - ok > 1) { long long mid = (ok + ng) / 2; (f(rh, a, a + mid) == f(rev, k * n - a - 1, k * n - a - 1 + mid) ? ok : ng) = mid; } cout << 2 * ok - 1 << '\n'; } }