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