import sys input = sys.stdin.readline N,Q=map(int,input().split()) S=input().strip() for queries in range(Q): H,W,P=map(int,input().split()) D=[0] R=[0] for s in S: D.append(D[-1]) R.append(R[-1]) if s=="D": D[-1]+=1 else: R[-1]+=1 # 何歩で下にたどりつくか? OK=2*(10**9)+10 NG=0 while OK>NG+1: mid=(OK+NG)//2 #print(mid,P,N) if mid+P<=N: down=D[mid+P]-D[P] right=R[mid+P]-R[P] #print("!",mid,down,right) else: down=D[-1]-D[P] right=R[-1]-R[P] midx=mid-(N-P) kk=midx//N rest=midx%N down+=kk*D[-1] right+=kk*R[-1] down+=D[rest] right+=R[rest] #print(mid,down,right) if H<=down or W<=right: OK=mid else: NG=mid print((OK+P)%N)