N,Q=map(int, input().split()) S=input() R,D=[0],[0] for s in S: R.append(R[-1]);D.append(D[-1]) if s=='R': R[-1]+=1 else: D[-1]+=1 import bisect for i in range(Q): h,w,p=map(int, input().split()) h+=D[p];w+=R[p] sh=D[-1] if sh!=0: ss=max(0,(h-1)//sh) sn=h-ss*sh p=bisect.bisect_left(D,sn) dd=ss*N+p else: dd=10**10 sh=R[-1] if sh!=0: ss=max(0,(w-1)//sh) sn=w-ss*sh p=bisect.bisect_left(R,sn) rr=ss*N+p else: rr=10**10 ans=min(dd,rr)%N print(ans)