#include using namespace std; #define ll long long #define rep(i,a,b) for(int i = a; i < b; i++) #define repl(i,a,b) for(ll i = a; i < b; i++) #define REP(i,a,b) for(int i = a; i <=b; i++) #define REPL(i,a,b) for(ll i = a; i <=b; i++) #define fore(i,a) for(auto &i : a) #define all(x) (x).begin(),(x).end() #define fix(i) fixed << setprecision(i) #define nextp(v) next_permutation(all(v)) templatebool chmax(T& a, const T& b) { if(a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if(b < a) { a = b; return 1; } return 0; } using pii = pair; using pll = pair; using pq = priority_queue; using pqll = priority_queue; const ll INF = LLONG_MAX/2; const ll MOD = 1000000007; struct Comb { vector fact, rfact; ll inv(int X) { ll Res = 1, K = MOD-2, Y = X; while(K) { if(K & 1) Res = (Res * Y) % MOD; Y = (Y * Y) % MOD; K /= 2; } return Res; } Comb(int N) { fact.resize(N); fact[0] = 1; rep(i,1,N) fact[i] = fact[i-1]*i % MOD; rfact.resize(N); rfact[N-1] = inv(fact[N-1]); for(int i = N-2; i >= 0; i--) rfact[i] = (rfact[i+1] * (i+1)) % MOD; } ll C(int N, int K) { if (K < 0 || N < K) return 0; ll A = fact[N], B = rfact[N-K], C = rfact[K]; ll BC = (B * C) % MOD; return (A * BC) % MOD; } ll P(int N, int K) { if (K < 0 || N < K) return 0; ll A = fact[N], B = rfact[N-K]; return (A * B) % MOD; } ll H(int N, int K) { if (N == 0 && K == 0) return 1; return C(N+K-1, K); } }; int main() { int N; cin >> N; Comb combo(1000001); rep(i,0,N) { char Type, Ignore; int A, B; cin >> Type >> Ignore >> A >> Ignore >> B >> Ignore; ll Res; if(Type == 'C') Res = combo.C(A, B); else if(Type == 'P') Res = combo.P(A, B); else if(Type == 'H') Res = combo.H(A, B); printf("%lld\n", Res); } }