#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define INF 1000000001 using ll = long long int; int main() { int N, Q; cin >> N >> Q; string S; cin >> S; vector h(N+1), w(N+1); rep(i, N) { h[i+1] = (S[i] == 'D') ? h[i] + 1 : h[i]; w[i+1] = (S[i] == 'R') ? w[i] + 1 : w[i]; } rep(j, Q) { int H, W, P; cin >> H >> W >> P; int h0 = (h[P % N] + H); int w0 = (w[P % N] + W); ll nh = INF, nw = INF; if (h[N] > 0) nh = (h0 % h[N] == 0) ? (ll)(h0 / h[N] - 1) * N : (ll)(h0 / h[N]) * N; if (w[N] > 0) nw = (w0 % w[N] == 0) ? (ll)(w0 / w[N] - 1) * N : (ll)(w0 / w[N]) * N; nh += lower_bound(h.begin(), h.end(), h0-(nh/N)*h[N]) - h.begin(); nw += lower_bound(w.begin(), w.end(), w0-(nw/N)*w[N]) - w.begin(); cout << min(nh, nw) % N << endl; } return 0; }