MOD = 10 ** 9 + 7 m = 2 * (10 ** 6) fact = [1 for _ in range(m + 1)] inv = [1 for _ in range(m + 1)] ifact = [1 for _ in range(m + 1)] for x in range(2, m + 1): inv[x] = (- (MOD // x) * inv[MOD % x]) % MOD fact[x] = (fact[x - 1] * x) % MOD ifact[x] = (ifact[x - 1] * inv[x]) % MOD def choose(n, k): if n < k: return 0 else: return fact[n] * ifact[n - k] * ifact[k] % MOD def permutation(n, k): if n < k: return 0 else: return fact[n] * ifact[n - k] % MOD def repeated_permutation(n, k): return fact[n + k - 1] * ifact[n - 1] * ifact[k] % MOD t = int(input()) for _ in range(t): ty, *args = list(input()) n, k = map(int, ''.join(args[1:-1]).split(',')) if ty == 'C': print(choose(n, k)) elif ty == 'P': print(permutation(n, k)) elif ty == 'H': print(repeated_permutation(n, k))