//#define PROBLEM "https://yukicoder.me/problems/184" // //#include "../../library/library/debug_template.cpp" //#include "../../library/library/Factorial.cpp" #include #include #include #include using namespace std; using lint = long long; constexpr int MOD = 1000000007; class Factorial { private: vector fac, inv, finv; void build(int N) { fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1; for (int i = 2; i < 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; } } public: Factorial(int N = 110000) : fac(N + 1), inv(N + 1), finv(N + 1) { build(N + 1); } lint Cmod(int n, int k) { if (n < k || k < 0) return 0LL; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } lint Pmod(int n, int k) { if (n < k || k < 0) return 0LL; return fac[n] * finv[n - k] % MOD; } }; int main() { Factorial F(200000); int t; scanf("%d\n", &t); for (int i = 0; i < t; i++) { char c; int n, k; scanf("%c(%d,%d)\n", &c, &n, &k); if (c == 'C') { printf("%lld\n", F.Cmod(n, k)); } else if (c == 'P') { printf("%lld\n", F.Pmod(n, k)); } else { printf("%lld\n", F.Cmod(n + k - 1, k)); } } return 0; }