#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(){ string S; ll K, Q; cin >> S >> K >> Q; ll N = S.size(); string T = ""; for(int i = 0; i < K; i++){ T += S; } vector A = manacher(T); while(Q--){ int pos; cin >> pos; pos--; cout << A[pos] * 2 - 1 << endl; } }