N, Q = map(int, input().split()) S = input().rstrip() D, R = [0] * N, [0] * N for i in range(N): if S[i] == "D": D[i] = 1 if S[i] == "R": R[i] = 1 SD, SR = [0] * (N + 1), [0] * (N + 1) for i in range(1, N + 1): SD[i] = SD[i - 1] + D[i - 1] SR[i] = SR[i - 1] + R[i - 1] for _ in range(Q): H, W, P = map(int, input().split()) left = 0; right = H + W while right - left > 1: mid = (left + right) // 2 Dn = SD[N] * ((P + mid) // N) + SD[(P + mid) % N] Dn -= SD[N] * (P // N) + SD[P % N] Rn = SR[N] * ((P + mid) // N) + SR[(P + mid) % N] Rn -= SR[N] * (P // N) + SR[P % N] if Dn >= H or Rn >= W: right = mid else: left = mid print((P + right) % N)