#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; string s; cin >> s; for(int i = 0; i < q; i++){ int h, w, p, x = 0, y = 0, c; cin >> h >> w >> p; c = p; for(int j = 0; j < (int)s.size(); j++){ if(x == h && y == w) break; if(x == h && y != w) { y++; x = h; }else if(x != h && y == w){ x++; y = w; }else { if(s[j] == 'D'){ x++; c++; c %= n; if(y == w) y = w; }else if(s[j] == 'R'){ y++; c++; c %= n; if(x == h) x = h; } } } cout << c << '\n'; } return 0; }