// #pragma GCC target("avx2,bmi2,popcnt,lzcnt") // #pragma GCC optimize("O3,unroll-loops") #include // #include using namespace std; using namespace numbers; #ifdef LOCAL #include "Debug.h" #else #define debug_endl() 42 #define debug(...) 42 #define debug2(...) 42 #define debug_bin(...) 42 #endif // Returns the largest integer k with x >= k * y template T floor_div(T x, U y){ assert(y > 0); return x / y - (x % y < 0); } // Returns the smallest integer k with x <= k * y template T ceil_div(T x, U y){ assert(y > 0); return x / y + (x % y > 0); } template T &ctmin(T &x){ return x; } template T &ctmin(T &x, const Head &h, const Tail &... t){ return ctmin(x = min(x, h), t...); } template T &ctmax(T &x){ return x; } template T &ctmax(T &x, const Head &h, const Tail &... t){ return ctmax(x = max(x, h), t...); } int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); const long long inf = numeric_limits::max() / 2; vector dp{1}; for(auto i = 0; i < 60; ++ i){ dp.push_back(min(inf, dp[i] + (5LL << i))); } int n, qn; string s; cin >> n >> qn >> s; vector pref(n + 1); for(auto i = 0; i < n; ++ i){ pref[i + 1] = pref[i] + ranges::contains("wa", s[i]); } for(auto qi = 0; qi < qn; ++ qi){ long long _level, pos; cin >> _level >> pos, -- pos; int level = min(_level, 60); int i = *ranges::partition_point(views::iota(1, n), [&](int len){ // first len does not contain ans if(__builtin_mul_overflow_p(dp[level], pref[len], 0LL) || dp[level] * pref[len] >= inf){ return false; } return len - pref[len] + dp[level] * pref[len] <= pos; }) - 1; pos -= i - pref[i] + dp[level] * pref[i]; if(!ranges::contains("wa", s[i])){ cout << s[i]; } else{ char c = s[i]; while(pos > 0){ assert(level > 0); assert(ranges::contains("wa", c)); string t = c == 'w' ? "warong" : "answer"; int i = 0; while(true){ long long x = ranges::contains("wa", t[i]) ? dp[min(level - 1, 60)] : 1; if(pos < x){ break; } pos -= x; ++ i; } c = t[i]; -- level; } cout << c; } } cout << "\n"; return 0; } /* */