from bisect import bisect_left n,q = map(int,input().split()) s = input()*2; d = [0]; r = [0] for v in s: d.append(d[-1]); r.append(r[-1]) if v=="D": d[-1] += 1 else: r[-1] += 1 for _ in range(q): h,w,p = map(int,input().split()) d1,d2 = divmod(h,d[n]); d3 = max(bisect_left(d,d[p]+d2),p) r1,r2 = divmod(w,r[n]); r3 = max(bisect_left(r,r[p]+r2),p) print(d3%n if (d1,d3)<(r1,r3) else r3%n)