import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int q = sc.nextInt(); int[][][] values = new int[31][n][2]; char[] inputs = sc.next().toCharArray(); for (int i = 0; i < n; i++) { if (inputs[i] == 'D') { values[0][i][0]++; } else { values[0][i][1]++; } } for (int i = 1; i <= 30; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < 2; k++) { values[i][j][k] = values[i - 1][j][k] + values[i - 1][(j + (1 << (i - 1))) % n][k]; } } } StringBuilder sb = new StringBuilder(); while (q-- > 0) { int h = sc.nextInt(); int w = sc.nextInt(); int p = sc.nextInt(); for (int i = 30; i >= 0; i--) { if (values[i][p][0] < h && values[i][p][1] < w) { h -= values[i][p][0]; w -= values[i][p][1]; p += (1 << i); p %= n; } } while (h > 0 && w > 0) { if (inputs[p] == 'D') { h--; } else { w--; } p++; p %= n; } sb.append(p).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }