#pragma warning(disable:4996) #include using namespace std; template class Combination { vector fact, factr, inv; Int mod; inline void init(int _N) { fact.resize(_N + 1); factr.resize(_N + 1); inv.resize(_N + 1); inv[1] = fact[0] = factr[0] = 1; for (int i = 2; i <= _N; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod; for (int i = 1; i <= _N; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod; } public: Combination(Int _mod, int _N) { mod = _mod; init(_N); } Int C(Int N_, Int R_) { if (R_<0 || R_>N_) return 0; return factr[R_] * fact[N_] % mod*factr[N_ - R_] % mod; } Int P(Int N_, Int R_) { if (R_<0 || R_>N_) return 0; return fact[N_] * factr[N_ - R_] % mod; } Int H(int N_, int R_) { if (N_ == 0 && R_ == 0) return 1; return C(N_ + R_ - 1, R_); } }; struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__; int main(void) { int T; cin >> T; Combination comb(1'000'000'007, 2'000'100); for (int i = 0; i < T; ++i) { char c; long long N, K; cin >> c; cin.ignore(); cin >> N; cin.ignore(); cin >> K; cin.ignore(); if (c == 'C') { cout << comb.C(N, K) << endl; } else if (c == 'P') { cout << comb.P(N, K) << endl; } else { cout << comb.H(N, K) << endl; } } return 0; }