N,Q = map(int,input().split()) S = input() HH = [0 for j in range(N+1)] WW = [0 for j in range(N+1)] h,w = 0,0 for i in range(N): if S[i] == 'D': h += 1 HH[h] = i + 1 else: w += 1 WW[w] = i + 1 for _ in range(Q): H,W,P = map(int,input().split()) if h > 0: hh = H % h if hh == 0: hh += h th = ((H - hh) // h)*N + HH[hh] else: th = 10**18 if w > 0: ww = W % w if ww == 0: ww += w tw = ((W - ww) // w)*N + WW[ww] else: tw = 10**18 ans = th % N if tw < th: ans = tw % N ans += P ans %= N print(ans)