N, Q = map(int, input().split()) S = input() acc_h = [0] acc_w = [0] for i in range(N): acc_h.append(acc_h[-1]) acc_w.append(acc_w[-1]) if S[i] == 'D': acc_h[-1] += 1 else: acc_w[-1] += 1 # print(acc_h, acc_w) for _ in range(Q): h, w, p = map(int, input().split()) ok = 1 << 60; ng = 0 while ok - ng > 1: mid = (ok + ng) >> 1 i = acc_h[N] * (mid // N) - acc_h[p] + acc_h[mid % N] j = acc_w[N] * (mid // N) - acc_w[p] + acc_w[mid % N] if i >= h or j >= w: ok = mid else: ng = mid print(ok % N)