class Bit: def __init__(self, n): self.size = n self.n0 = 1 << (n.bit_length() - 1) self.tree = [0] * (n + 1) def range_sum(self, l, r): return self.sum(r - 1) - self.sum(l - 1) def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def get(self, i): return self.sum(i) - self.sum(i - 1) def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): pos = 0 plus = self.n0 while plus > 0: if pos + plus <= self.size and self.tree[pos + plus] < x: x -= self.tree[pos + plus] pos += plus plus //= 2 return pos n, Q = map(int, input().split()) def start(t, x, lr): t %= (2 * n) while t > 0: if lr == "R": if x == 0: t -= 1 lr = "L" else: d = x mi = min(t, d) t -= mi x -= mi else: if x == n - 1: t -= 1 lr = "R" else: d = n - 1 - x mi = min(t, d) t -= mi x += mi return x, lr L = Bit(n) R = Bit(n) for _ in range(Q): query = input().split() t, y, z = map(int, query[1:]) if query[0] == "L": p, lr = start(t, y, "L") if lr == "L": L.add(p, z) else: R.add(p, z) elif query[0] == "R": p, lr = start(t, y, "R") if lr == "L": L.add(p, z) else: R.add(p, z) else: ans = 0 z -= 1 p1, lr1 = start(t, y, "L") p2, lr2 = start(t, z, "L") if lr1 == lr2: if p1 > p2: p1, p2 = p2, p1 if lr1 == "L": ans += L.range_sum(p1, p2 + 1) else: ans += R.range_sum(p1, p2 + 1) elif lr1 == "L": ans += L.range_sum(p1, n) + R.range_sum(p2, n) else: ans += R.range_sum(0, p1 + 1) + L.range_sum(0, p2 + 1) p1, lr1 = start(t, y, "R") p2, lr2 = start(t, z, "R") if lr1 == lr2: if p1 > p2: p1, p2 = p2, p1 if lr1 == "L": ans += L.range_sum(p1, p2 + 1) else: ans += R.range_sum(p1, p2 + 1) elif lr1 == "R": ans += R.range_sum(p1, n) + L.range_sum(p2, n) else: ans += L.range_sum(0, p1 + 1) + R.range_sum(0, p2 + 1) print(ans)