#include using namespace std; using ll = long long; vector manacher(string s){ int i = 0, j = 0; vector res(s.size()); while (i < s.size()) { while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) ++j; res[i] = j; int k = 1; while (i - k >= 0 && i + k < s.size() && k + res[i - k] < j) res[i + k] = res[i - k], ++k; i += k; j -= k; } return res; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll N, K, Q; string S; cin >> N >> K >> Q >> S; string T = ""; for(int i = 0; i < min(K, 3LL); i++){ T += S; } vector A = manacher(T); while(Q--){ ll pos, ans = -1; cin >> pos; pos--; if(K <= 3){ ans = A[pos]; }else{ if(2 * A[N + pos % N] - 1 >= 2 * N + 1){ ans = min(pos, K * N - 1 - pos) + 1; }else{ if(pos < N) ans = A[pos]; else if((K - 1) * N <= pos) ans = A[2 * N + pos % N]; else ans = A[N + pos % N]; } } cout << 2 * ans - 1 << endl; } }