N,Q=map(int,input().split()) S=input() rs=[0 for _ in range(N)] ls=[0 for _ in range(N)] for i in range(N): if S[i]=='R': rs[i]+=1 else: ls[i]+=1 if i!=0: rs[i]+=rs[i-1] ls[i]+=ls[i-1] import bisect def solve(dat,n): if n%dat[-1]==0: return n//dat[-1]*N+(N-1-bisect.bisect_left(dat,dat[-1])) re=0 re+=n//dat[-1]*N #print('!',dat,n,re) re+=bisect.bisect_left(dat,n%dat[i])+1 return re rss=rs+[0] lss=ls+[0] #print(rss,lss) for _ in range(Q): H,W,P=map(int,input().split()) #print(rss[P-1]+W,lss[P-1]+H) r=solve(rs,rss[P-1]+W) l=solve(ls,lss[P-1]+H) #print(r,l) if r>l: print(l%N) else: print(r%N)