#include //#include using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template T binarySearch(T ok, T ng, const F &f) { while (abs(ok - ng) > 1) { T mid = (ok + ng) / 2; (f(mid) ? ok : ng) = mid; } return ok; } long long c0[26][61]; long long c1[26][61]; long long c2[26][61]; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, q; cin >> n >> q; string s; cin >> s; string ans; rep(i, 26) { if (i == ('a' - 'a') || i == ('w' - 'a'))c0[i][0] = 1; else c1[i][0] = 1; c2[i][0] = 1; } rep(i, 61) rep(c, 26) { int ni = i + 1; c0[c][ni] = min(LINF + 10, c0[c][i] * 2); c1[c][ni] = min(LINF + 10, c1[c][i] + c0[c][i] * 4); c2[c][ni] = min(LINF + 10, c0[c][ni] + c1[c][ni]); } while (q--) { long long t, x; cin >> t >> x; x--; t = min(t, 60LL); auto from = [&](const long long target)->bool { long long ret = 0; rep(i, target + 1) { ret = (LINF + 1000, ret + c2[s[i] - 'a'][t]); } return ret > x; }; int index = binarySearch(s.size() - 1, -1, from); // 不要分を計算する auto remove = [&](int index)->long long { long long c0 = 0, c1 = 0; rep(i, index) { if (s[i] == 'a' || s[i] == 'w')c0++; else c1++; } if (c0 == 0) { return c0 + c1; } for (long long i = 0; i < t; ++i) { c1 += c0 * 4; c0 *= 2; } return c0 + c1; }; x -= remove(index); auto count = [&](const char c, int cnt)->long long { long long c0 = 0, c1 = 0; if (c == 'a' || c == 'w')c0++; else c1++; rep(i, cnt) { c1 += c0 * 4; c0 *= 2; if (c0 + c1 > LINF * 2)return LINF * 2;// over flow??? } return c0 + c1; }; // cのn回後のx文字目 auto solve = [&](auto &&self, char c, long long n, long long x)->char { return 'a'; // cout << c << " " << n << " " << x << endl; if (c != 'a' && c != 'w')return c; string tmp; if (c == 'a') { tmp = "answer"; } else if (c == 'w') { tmp = "warong"; } if (n == 1)return tmp[x]; long long pre = 0; rep(i, tmp.size()) { // cout << tmp[i] - 'a' << "!" << n - 1 << endl; // cout << c2[tmp[i] - 'a'][n - 1] << "!!" << count(tmp[i], n - 1) << endl; auto cnt = c2[tmp[i] - 'a'][n - 1];// count(tmp[i], n - 1); //auto cnt = count(tmp[i], n - 1); // cout << cnt << endl; if (pre + cnt > x) { return self(self, tmp[i], n - 1, x - pre); } else { pre += cnt; } } }; ans += solve(solve, s[index], t, x); // cout << solve(solve, s[index], t, x) << endl; } cout << ans << endl; return 0; }