#include #include #include #include #include #include #include using namespace std; namespace{ typedef long long LL; template ::value_type> > std::vector manacher(RIter s, RIter en, const Comparer &eqcomp = Comparer()){ int i = 0, j = 0; int n = std::distance(s, en); std::vector res(n); while (i < n){ while(i - j >= 0 && i + j < n && eqcomp(s[i - j], s[i + j])){ ++j; } res[i] = j; int k = 1; while(i - k >= 0 && i + k < n && k + res[i - k] < j){ res[i + k] = res[i - k]; ++k; } i += k; j -= k; } return res; } void main2(){ ios::sync_with_stdio(false); cin.tie(0); int n, q; LL k; string s; cin >> n >> k >> q >> s; string u = s + s + s + s + s; vector mn = manacher(u.begin(), u.end()); for(; q--; ){ LL a; cin >> a; --a; int b = a % n; LL z = mn[b + 2 * n]; if(z > n){ z = k * n; } z = min({z, a + 1, k * n - a}); cout << (z * 2 - 1) << '\n'; } } } int main(){ main2(); }