import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random input = sys.stdin.readline #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) #input = sys.stdin.readline n,q = map(int,input().split()) s = list(input().rstrip()) d = s.count('D') r = s.count('R') dd = [] rr = [] for i in range(n): dd.append(1 if s[i] == 'D' else 0) rr.append(1 if s[i] == 'R' else 0) for i in range(n): dd.append(1 if s[i] == 'D' else 0) rr.append(1 if s[i] == 'R' else 0) dd = list(itertools.accumulate(dd)) rr = list(itertools.accumulate(rr)) for i in range(q): h,w,p = map(int,input().split()) z = min(h//d if d != 0 else 10**18,w//r if r != 0 else 10**18) h = h - d * z w = w - r * z if h == 0 or w == 0: h += d w += r #print(h,w) di = bisect.bisect_left(dd,(dd[p-1] if p != 0 else 0)+h) ri = bisect.bisect_left(rr,(rr[p-1] if p != 0 else 0)+w) #print(di,ri) j = min(di,ri)+1 print((j)%n)