n,q=map(int,input().split()) S=input() D=[1 if S[0]=='D' else 0] d=[0] if S[0]=='D' else [] R=[1 if S[0]=='R' else 0] r=[0] if S[0]=='R' else [] for i in range(1,n): if S[i]=='D': D.append(D[-1]+1) R.append(R[-1]) d.append(i) elif S[i]=='R': D.append(D[-1]) R.append(R[-1]+1) r.append(i) for i in range(q): h,w,p=map(int,input().split()) cycle=min(h//len(d),w//len(r)) y=h-len(d)*cycle x=w-len(r)*cycle residue=0 if y=len(r): residue=d[(y+D[p])%len(d)]-D[p] elif y>=len(d) and x