#include using namespace std; using i64 = int_fast64_t; using ui64 = uint_fast64_t; #define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i)) #define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i)) const ui64 MAX = 2020202; const ui64 MOD = (i64)1e9 + 7; ui64 fac[MAX], finv[MAX], inv[MAX]; void init() { fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1; for (i64 i = 2; i < MAX; ++i) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ui64 C(i64 n, i64 r) { if (n < r or r < 0) return 0; return (fac[n] * ((finv[n - r] * finv[r]) % MOD)) % MOD; } ui64 P(i64 n, i64 r) { if (r < 0 or n < r) return 0; else return (fac[n] * finv[n - r]) % MOD; } ui64 H(i64 n, i64 r) { if (n == 0 and r == 0) return 1; else return C(n + r - 1, r); } signed main() { cin.tie(0); ios::sync_with_stdio(false); init(); int N; cin >> N; REP(i, N) { char in; cin >> in; char dust; cin >> dust; i64 a, b; cin >> a >> dust >> b >> dust; if (in == 'C') { cout << C(a, b) << endl; } else if (in == 'P') { cout << P(a, b) << endl; } else { cout << H(a, b) << endl; } } }