#!/usr/bin/env python3 # † mod = 10**9 + 7 ### if __name__ == '__main__': N = 2 * 10**6 + 6 nume = [None] * N deno = [None] * N nume[0] = 1 deno[0] = pow(nume[0], -1, mod) for i in range(N-1): nume[i+1] = nume[i] * (i+1) % mod deno[i+1] = pow(nume[i+1], -1, mod) def C(n, k): if n < k: return 0 return nume[n] * deno[k] * deno[n-k] % mod def P(n, k): if n < k: return 0 return nume[n] * deno[n-k] % mod def H(n, k): if (n, k) == (0, 0): return 1 return C(n+k-1, k) T = int(input()) for _ in range(T): line = input() a, (N, K) = line[0], map(int, line[2:-1].split(',')) if a == 'C': res = C(N, K) elif a == 'P': res = P(N, K) else: res = H(N, K) print(res)