from bisect import bisect_left as bl N,Q = map(int,input().split()) S = list(input()) csum = [(0,0)] INF = 10**10 for i in range(len(S)): h,w = csum[i] if S[i] == "R": csum.append((h,w+1)) elif S[i] == "D": csum.append((h+1,w)) def bs(csum,m,i,l,r): if l > r: return r p = (l+r)//2 x = csum[p][i] if x < m: return bs(csum,m,i,p+1,r) else: return bs(csum,m,i,l,p-1) for _ in range(Q): h,w,p = map(int,input().split()) x,y = csum[p] g = (h+x,w+y) ht = g[0]//csum[-1][0] if csum[-1][0] != 0 else INF wt = g[1]//csum[-1][1] if csum[-1][1] != 0 else INF hm = g[0]%csum[-1][0] if csum[-1][0] != 0 else INF wm = g[1]%csum[-1][1] if csum[-1][1] != 0 else INF hidx = bs(csum,hm,0,0,N) + 1 widx = bs(csum,wm,1,0,N) + 1 if ht*N+hidx > wt*N+widx: print(widx) else: print(hidx)