n,Q=map(int,input().split()) s=input() R=[0] D=[0] for i in s: if i=="R": R.append(R[-1]+1) D.append(D[-1]) else: D.append(D[-1]+1) R.append(R[-1]) def Rco(start,dist): g=start+dist syu=g//n div=g%n return R[-1]*syu+R[div]-R[start] def Dco(start,dist): g=start+dist syu=g//n div=g%n return D[-1]*syu+D[div]-D[start] for i in range(Q): d,r,p=map(int,input().split()) ans=0 for bs in reversed(range(40)): ans+=2**bs #print(Dco(p,ans),Rco(p,ans)) if Dco(p,ans)>=d or Rco(p,ans)>=r: ans-=2**bs print((p+ans+1)%n) """ for i in range(5): for j in range(5): print(Rco(i,j)) print("#") """