mod = 10 ** 9 + 7 class combinatorics: def __init__(self, n): self.n = n self.fa = [1] * (self.n * 2 + 1) self.fi = [1] * (self.n * 2 + 1) for i in range(1, self.n * 2 + 1): self.fa[i] = self.fa[i - 1] * i % mod self.fi[-1] = pow(self.fa[-1], mod - 2, mod) for i in range(self.n * 2, 0, -1): self.fi[i - 1] = self.fi[i] * i % mod def comb(self, n, r): if n < r:return 0 if n < 0 or r < 0:return 0 return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod def perm(self, n, r): if n < r:return 0 if n < 0 or r < 0:return 0 return self.fa[n] * self.fi[n - r] % mod def cwr(self, n, r): return self.comb(n + r - 1, r) C = combinatorics(10 ** 6) for _ in range(int(input())): Q = input() n, k = map(int, Q[2:-1].split(",")) if Q[0] == "C": print(C.comb(n, k)) elif Q[0] == "P": print(C.perm(n, k)) else: print(C.cwr(n, k))