#include using namespace std; using ull = unsigned long long; const ull INF = 1000000000000000000ULL; const int MAXT = 60; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; string S; cin >> S; struct Query { unsigned long long T, X; int idx; }; vector qs(Q); for(int i = 0; i < Q; i++){ cin >> qs[i].T >> qs[i].X; qs[i].idx = i; } // Precompute lengths: len[c][t] = length of expansion of char c after t replacements static ull len[26][MAXT+1]; for(int c = 0; c < 26; c++){ len[c][0] = 1; } string rep_a = "answer"; string rep_w = "warong"; for(int t = 1; t <= MAXT; t++){ for(int c = 0; c < 26; c++){ char ch = 'a' + c; ull v = 0; if(ch == 'a'){ for(char d: rep_a){ v = min(INF, v + len[d-'a'][t-1]); } } else if(ch == 'w'){ for(char d: rep_w){ v = min(INF, v + len[d-'a'][t-1]); } } else { v = 1; } len[c][t] = v; } } // Gather distinct clamped times vector times; times.reserve(Q); for(auto &q: qs){ int t = (q.T > (unsigned long long)MAXT ? MAXT : (int)q.T); times.push_back(t); } sort(times.begin(), times.end()); times.erase(unique(times.begin(), times.end()), times.end()); // Prepare prefix sums for each distinct time // pre[t][i] = sum of lengths of S[0..i-1] at time t, clamped to INF vector> pre(MAXT+1); for(int t: times){ auto &P = pre[t]; P.assign(N+1, 0ULL); for(int i = 0; i < N; i++){ ull add = len[S[i]-'a'][t]; P[i+1] = P[i] + add < INF ? P[i] + add : INF; } } // Recursive function to get k-th char of expansion of c after t steps function get_char = [&](char c, int t, ull k)->char { if(t == 0 || (c != 'a' && c != 'w')){ // either no more replacements or this char never expands return c; } const string &rep = (c == 'a' ? rep_a : rep_w); for(char d: rep){ ull clen = len[d-'a'][t-1]; if(k <= clen){ return get_char(d, t-1, k); } k -= clen; } // should never reach here return '?'; }; // Answer each query string answer(Q, '?'); for(auto &q: qs){ int t = (q.T > (unsigned long long)MAXT ? MAXT : (int)q.T); auto &P = pre[t]; // binary search for the block in S int pos = int(lower_bound(P.begin()+1, P.end(), q.X) - P.begin()) - 1; // pos in [0..N-1], and P[pos] < X <= P[pos+1] ull offset = q.X - P[pos]; char c0 = S[pos]; answer[q.idx] = get_char(c0, t, offset); } // output cout << answer << "\n"; return 0; }