from itertools import accumulate from bisect import bisect_left, bisect_right N, Q = map(int, input().split()) S = [*input()] D = [int(ch == "D") for ch in S] R = [int(ch == "R") for ch in S] Dwa = [0] + [*accumulate(D)] Rwa = [0] + [*accumulate(R)] DELTA = sum(D) RHO = sum(R) def estimate_time(X, P, PI, wa): t = 0 q, r = divmod(X, PI) t += q*N X = r tail = wa[N] - wa[P] if tail < X: X -= tail t += N-P i = 0 else: i = P j = bisect_left(wa, wa[i] + X) t += j-i return t def solve(H, W, P): t_D = estimate_time(H, P, DELTA, Dwa) t_R = estimate_time(W, P, RHO, Rwa) t = min(t_D, t_R) return (P+t)%N for _ in range(Q): H, W, P = map(int, input().split()) ans = solve(H, W, P) print(ans)