// #pragma GCC optimize("O3,unroll-loops") #include // #include using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n, qn; string s; cin >> n >> qn >> s; vector> delta(n + 1); for(auto i = 0; i < n; ++ i){ delta[i + 1] = delta[i]; ++ delta[i + 1][s[i] == 'R']; } for(auto qi = 0; qi < qn; ++ qi){ int h, w, init; cin >> h >> w >> init; int move = *ranges::partition_point(ranges::iota_view(0, h + w), [&](int move){ auto [q, r] = div(move, n); long long x = 1LL * delta[n][0] * q, y = 1LL * delta[n][1] * q; if(init + r <= n){ x += delta[init + r][0] - delta[init][0]; y += delta[init + r][1] - delta[init][1]; } else{ x += delta[n][0] - delta[init][0] + delta[init + r - n][0]; y += delta[n][1] - delta[init][1] + delta[init + r - n][1]; } return x < h && y < w; }) % n; cout << (init + move) % n << "\n"; } return 0; } /* */