#include #include #include using namespace std; typedef long long ll; int T; const int MAX = 1000000; const ll MOD = pow(10,9)+7; vector fct(1000001); vector invfct(1000001); ll mpow(ll x, ll n){ //x^n(mod M) ll ans = 1; while(n != 0){ if(n&1) ans = ans*x % MOD; x = x*x % MOD; n = n >> 1; } return ans; } ll comb(ll a, ll b){ //aCb(mod M) if(a == 0 && b == 0)return 1; if(a < b || a < 0)return 0; ll tmp = invfct[a-b]* invfct[b] % MOD; return tmp * fct[a] % MOD; } ll perm(ll a, ll b){ if(a < b) return 0; ll tmp = invfct[a-b] % MOD; return tmp * fct[a] % MOD; } ll dupc(ll a,ll b){ if(a == 0 && b == 0)return 1; if(a < 0 || b == 0)return 0; ll tmp = invfct[a-1]* invfct[b] % MOD; return tmp * fct[a+b-1] % MOD; } int main(void){ // Your code here! fct[0] = 1; invfct[0] = 1; for(ll i = 0; i < 1000000; i++){ fct[i+1] = fct[i] * (i+1) % MOD; invfct[i+1] = invfct[i] * mpow(i+1, MOD-2) % MOD; } cin >> T; vector c(T); vector a(T),b(T); for(int i = 0; i < T; i++){ scanf(" %c(%d,%d)",&c[i] ,&a[i] ,&b[i]); } for(int i =0 ; i < T; i++){ ll ans = 0; if(c[i] == 'P') ans = perm(a[i], b[i]); if(c[i] == 'H') ans = dupc(a[i], b[i]); if(c[i] == 'C') ans = comb(a[i], b[i]); cout << ans << endl; } return 0; }