#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; template< int mod > struct Fp { int x; Fp() : x(0) {} Fp(int64_t y) : x(y >= 0 ? y % mod : (mod + y % mod) % mod) {} Fp &operator+=(const Fp &p) { if((x += p.x) >= mod) x -= mod; return *this; } Fp &operator-=(const Fp &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } Fp &operator*=(const Fp &p) { x = (int)(1LL * x * p.x % mod); return *this; } Fp &operator/=(const Fp &p) { *this *= p.inverse(); return *this; } Fp operator-() const { return Fp(-x); } Fp operator+(const Fp &p) const { return Fp(*this) += p; } Fp operator-(const Fp &p) const { return Fp(*this) -= p; } Fp operator*(const Fp &p) const { return Fp(*this) *= p; } Fp operator/(const Fp &p) const { return Fp(*this) /= p; } bool operator==(const Fp &p) const { return x == p.x; } bool operator!=(const Fp &p) const { return x != p.x; } Fp inv() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return Fp(u); } Fp pow(int64_t n) const { Fp ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const Fp &p) { return os << p.x; } friend istream &operator>>(istream &is, Fp &a) { int64_t t; is >> t; a = Fp< mod > (t); return (is); } static int get_mod() { return mod; } }; template struct Mod_package { vector< T > fact_, inv_, finv_; constexpr Mod_package(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) { int mod = fact_[0].get_mod(); for(int i = 2; i < n; i++){ fact_[i] = fact_[i - 1] * i; inv_[i] = -inv_[mod % i] * (mod / i); finv_[i] = finv_[i - 1] * inv_[i]; } } constexpr T comb(int n, int k) const noexcept { if(n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[k] * finv_[n - k]; } constexpr T perm(int n, int k) const noexcept { if(n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[n - k]; } constexpr T hom(int n, int k) const noexcept { if(n < 0 || k < 0 || (n == 0 && k > 0)) return 0; if(n == 0 && k == 0) return 1; return fact_[n + k - 1] * finv_[k] * finv_[n - 1]; } constexpr T fact(int n) const noexcept { if(n < 0) return 0; return fact_[n]; } constexpr T inv(int n) const noexcept { if(n < 0) return 0; return inv_[n]; } constexpr T finv(int n) const noexcept { if(n < 0) return 0; return finv_[n]; } }; using mint = Fp<1000000007>; int main(){ cin.tie(0); ios::sync_with_stdio(0); Mod_package mp(2020202); int T; cin >> T; while(T--) { char c,d; int N,K; cin >> c >> d >> N >> d >> K >> d; if(c == 'C') printf("%d\n", mp.comb(N, K)); if(c == 'P') printf("%d\n", mp.perm(N, K)); if(c == 'H') printf("%d\n", mp.hom(N, K)); } }