from itertools import accumulate from bisect import bisect_left N,Q = map(int,input().split()) S = input() X = [[0] * (N+1) for _ in range(2)] INF = 10 ** 10 for i,s in enumerate(S,start = 1): if s == "D": X[0][i] = 1 else: X[1][i] = 1 for i in range(2): X[i] += X[i][1:] X[i] = list(accumulate(X[i])) ht,wt = X[0][N],X[1][N] def solve(): h,w,p = map(int,input().split()) if ht > 0: rh = h // ht else: rh = INF if wt > 0: rw = w // wt else: rw = INF if rh < rw: ans = N * rh ans += bisect_left(X[0],h % ht + X[0][p]) ans %= N elif rh > rw: ans = N * rw ans += bisect_left(X[1],w % wt + X[1][p]) ans %= N else: tmp1 = N * rh tmp1 += bisect_left(X[0],h % ht + X[0][p]) tmp2= N * rw tmp2 += bisect_left(X[1],w % wt + X[1][p]) ans = min(tmp1,tmp2) % N print(ans) for _ in range(Q): solve()