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 else: w += 1 WW[w] = i for _ in range(Q): H,W,P = map(int,input().split()) hh = H % h if hh == 0: hh += h th = ((H - hh) // h)*N + HH[hh] ww = W % w if ww == 0: ww += w tw = ((W - ww) // w)*N + WW[ww] ans = (th + 1) % N if tw < th: ans = (tw + 1) % N ans += P ans %= N print(ans)