#include using namespace std; using i64 = int_fast64_t; using ui64 = uint_fast64_t; #define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i)) #define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i)) constexpr bool EXPAND_TO_MINUS = true; constexpr int MOD = (int)1e9 + 7; constexpr int MAX_N = 2020202; uint_fast64_t fac[MAX_N], finv[MAX_N], inv[MAX_N]; void COMinit() { fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1; for (int i = 2; i < MAX_N; ++i) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } uint_fast64_t C(int n, int r) { if (n == 0 or n < r or r < 0) return 0; if (n < 0) return EXPAND_TO_MINUS ? ((r % 2 ? -1 : 1) * C(-n + r - 1, r)) : 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } uint_fast64_t P(int n, int r) { if (n < r or r < 0) return 0; return (fac[n] * finv[n - r]) % MOD; } uint_fast64_t H(int n, int r) { if (n == 0 and r == 0) return 1; return C(n + r - 1, r); } int main() { COMinit(); int Q; scanf("%d\n" , &Q); while (Q--) { int N, K; char c; scanf("%c(%d,%d)\n", &c, &N, &K); if (c == 'C') cout << C(N ,K) << '\n'; if (c == 'P') cout << P(N, K) << '\n'; if (c == 'H') cout << H(N, K) << '\n'; } }