import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 class Cumsum1d(): def __init__(self, A): self.n = len(A) self.Suma = [0] * (self.n + 1) for i in range(self.n): self.Suma[i + 1] += self.Suma[i] + A[i] def query(self, l, r): #0-indexed return self.Suma[r] - self.Suma[l] def get(self, i): return self.Suma[i + 1] - self.Suma[i] def __getitem__(self, p): if isinstance(p, int): return self.get(p) else: return self.query(p.start, p.stop) n, q = mi() s = input() R = [0] * n D = [0] * n for i in range(n): if s[i] == 'R': R[i] = 1 else: D[i] = 1 R = Cumsum1d(R) D = Cumsum1d(D) def countr(p, d): #p項目からd項にわたるrの個数 ret = 0 if n - p <= d: ret += R.query(p, n) d -= n - p ret += (d // n) * R.query(0, n) ret += R.query(0, d % n) else: ret += R.query(p, p + d) return ret def countd(p, d): #p項目からd項にわたるdの個数 ret = 0 if n - p <= d: ret += D.query(p, n) d -= n - p ret += (d // n) * D.query(0, n) ret += D.query(0, d % n) else: ret += D.query(p, p + d) return ret for i in range(q): h, w, p = mi() ok = h + w + 100 ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 r = countr(p, mid) d = countd(p, mid) if d >= h or r >= w: ok = mid else: ng = mid print((p + ok) % n)