#include using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const int MAX = 2000100; ll fact[MAX], inv[MAX], fact_inv[MAX]; inline ll P(int n, int k){ if(k > n)return 0; return fact[n] * fact_inv[n-k] % MOD; } inline ll C(int n, int k){ if(k > n)return 0; ll res = fact[n]; res = (res * fact_inv[k]) % MOD; res = (res * fact_inv[n-k]) % MOD; return res; } inline ll H(int n, int k){ return C(n + k - 1, k); } int main(){ fact[0] = 1; for(int i=1;i> T; while(T--){ string line; cin >> line; char cmd; int N, K; sscanf(line.c_str(), "%c(%d,%d)", &cmd, &N, &K); ll res; if(cmd == 'P')res = P(N, K); if(cmd == 'C')res = C(N, K); if(cmd == 'H')res = H(N, K); cout << res << endl; } return 0; }