n, Q = map(int, input().split()) S = input() H = [0] W = [0] H2 = [0] W2 = [0] for i, s in enumerate(S, 1): if s == "D": H.append(i) H2.append(H2[-1] + 1) W2.append(W2[-1]) else: W.append(i) H2.append(H2[-1]) W2.append(W2[-1] + 1) for _ in range(Q): h, w, p = map(int, input().split()) h += H2[p] w += W2[p] if H2[-1] == 0: print(w % n) continue if W2[-1] == 0: print(h % n) continue mi = min((h - 1) // H2[-1], (w - 1) // W2[-1]) h -= mi * H2[-1] w -= mi * W2[-1] ans = n if h <= H2[-1]: ans = min(ans, H[h]) if w <= W2[-1]: ans = min(ans, W[w]) print(ans % n)