#include using namespace std; typedef long long int ll; typedef pair pii; typedef vector vi; typedef vector > vii; #define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++) #define erep(i, m, n) for(ll (i)=(m); (i)<=(n); (i)++) #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) #define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--) #define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template inline void minup(T1& m, T2 x){ if(m>x) m=static_cast(x); } template inline void maxup(T1& m, T2 x){ if(m(x); } #define INF 1000000000 #define MOD 1000000007LL #define EPS 1E-9 const int MAX_N = 1000000; const int mn = 2 * MAX_N + 1; int n, k; ll fact[mn]; int t; char q; 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 modInverse(ll a, ll m) { ll x, y; extgcd(a, m, x, y); return (m + x % m) % m; } int main() { fact[0] = 1LL; erep(i, 1, mn) fact[i] = (fact[i-1] * i) % MOD; scanf("%d%*c", &t); while(t--){ scanf("%c(%d,%d)%*c", &q, &n, &k); if(q == 'C'){ if(n < k) cout << 0 << endl; else cout << (fact[n] * modInverse((fact[k] * fact[n-k]) % MOD, MOD)) % MOD << endl; continue; } if(q == 'P'){ if(n < k) cout << 0 << endl; else cout << (fact[n] * modInverse(fact[n-k], MOD)) % MOD << endl; continue; } if(q == 'H'){ if(n == 0) cout << 0 << endl; else cout << (fact[n+k-1] * modInverse((fact[k] * fact[n-1]) % MOD, MOD)) % MOD << endl; } } return 0; }