#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define rep2(i, j, n) for (int i = j; i < (int)n; i++) int main() { int N, Q; cin >> N >> Q; string S; cin >> S; rep(j, Q) { int H, W, P; cin >> H >> W >> P; int x = 0, y = 0; int i = P; while (1) { if (x == H && y == W) { cout << i << endl; break; } else if (x == H) { y += 1; } else if (y == W) { x += 1; } else if (S[i] == 'D') { x += 1; i = (i + 1) % N; } else if (S[i] == 'R') { y += 1; i = (i + 1) % N; } } } return 0; }