import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int q = Integer.parseInt(sa[1]); char[] s = br.readLine().toCharArray(); int[] h = new int[q]; int[] w = new int[q]; int[] p = new int[q]; for (int i = 0; i < q; i++) { sa = br.readLine().split(" "); h[i] = Integer.parseInt(sa[0]); w[i] = Integer.parseInt(sa[1]); p[i] = Integer.parseInt(sa[2]); } br.close(); long[][] dpd = new long[31][n]; long[][] dpr = new long[31][n]; long inf = 1000000000000000000L; long d = inf; long r = inf; for (int i = 0; i < n; i++) { if (s[i] == 'D') { d = n + i; break; } } for (int i = 0; i < n; i++) { if (s[i] == 'R') { r = n + i; break; } } for (int i = n - 1; i >= 0; i--) { dpd[0][i] = d - i; dpr[0][i] = r - i; if (s[i] == 'D') { d = i; } else { r = i; } } for (int i = 0; i < 30; i++) { for (int j = 0; j < n; j++) { dpd[i + 1][j] = dpd[i][j] + dpd[i][(int) ((j + dpd[i][j]) % n)]; dpr[i + 1][j] = dpr[i][j] + dpr[i][(int) ((j + dpr[i][j]) % n)]; dpd[i + 1][j] = Math.min(dpd[i + 1][j], inf); dpr[i + 1][j] = Math.min(dpr[i + 1][j], inf); } } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { if (s[p[i]] == 'D') { h[i]--; } else { w[i]--; } d = p[i]; for (int j = 0; j < 31; j++) { if ((h[i] >> j & 1) == 1) { d += dpd[j][(int) (d % n)]; } } r = p[i]; for (int j = 0; j < 31; j++) { if ((w[i] >> j & 1) == 1) { r += dpr[j][(int) (r % n)]; } } long ans = Math.min(d + 1, r + 1) % n; pw.println(ans); } pw.flush(); } }