#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define rep2(i, l, r) for (int i = (l); i < (r); i++) #define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--) #define range(a) a.begin(), a.end() using namespace std; using ll = long long; vector manacher(string s) { const int n = s.size(); vector rad(n); int i = 0; int k = 0; while (i < n) { while (i-k-1>=0 && i+k+1> N >> K >> Q; string S; cin >> S; auto m1 = manacher(S + S + S); auto m2 = manacher(S + S + S + S + S); while (Q--) { ll A; cin >> A; A--; ll r1 = m1[A % N + N]; ll r2 = m2[A % N + 2*N]; if (r1 != r2) { cout << min(A, N*K-1-A)*2+1 << endl; continue; } cout << min(r2, min(A, N*K-1-A))*2+1 << endl; } }