#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; iDUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this< ostream& operator<<(ostream& os, vector const& v){ rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" "); return os; } ll const mod = 1000000007; int const MAX_N = 3000000; // ll inv[MAX_N+1]; // void build_inverse(){ // inv[1] = 1; // for(int i = 2; i <= MAX_N; i++){ // inv[i] = inv[mod%i]*(mod-mod/i)%mod; // } // } ll fact[MAX_N+1]; void build_factrial(){ fact[0] = fact[1] = 1; for(int i = 1; i < MAX_N; i++){ fact[i+1] = fact[i]*(i+1)%mod; } } ll extgcd(ll a, ll b, ll& x, ll& y) { ll d = a; if(b != 0){ d = extgcd(b,a%b,y,x); y -= (a/b)*x; } else { x=1; y=0; } return d; } ll mod_inverse(ll a, ll m) { ll x, y; extgcd(a, m, x, y); return (m + x % m) % m; } ll inv(ll a){ return mod_inverse(a,mod); } ll nPr(ll n, ll r){ if(r < 0 || n < r) return 0; return fact[n] * inv(fact[n-r]) % mod; } ll nCr(ll n, ll r){ if(r < 0 || n < r) return 0; return nPr(n,r) * inv(fact[r]) % mod; } int main(){ // build_inverse(); build_factrial(); int T; while(cin >> T){ rep(i,T){ char c; int N, K; dump(c,N,K); scanf("\n%c(%d,%d)",&c,&N,&K); if(c=='C') cout << nCr(N,K); if(c=='P') cout << nPr(N,K); if(c=='H') cout << nCr(N+K-1,N); cout << endl; } } }