#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)); } }; 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); while (q--) { long long a; cin >> a; --a; long long b = k * n - a - 1; int ok = 1, ng = n + 1; while (ng - ok > 1) { int mid = (ok + ng) / 2; (rh.get(a % n, a % n + mid) == rev.get(b % n, b % n + mid) ? ok : ng) = mid; } long long res = ok < n ? 2 * ok - 1 : k * n; res = min(res, 2 * min(k * n - a, a + 1) - 1); cout << res << '\n'; } }