#include #define rep(i,a,b) for(int i=int(a);i fact(2000010); ll powmod(ll x,ll n){ if(n == 0)return 1; ll ans = powmod(x*x%MOD,n/2); if(n % 2)ans = ans * x % MOD; return ans; } ll divmod(ll a,ll b){ return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD; } ll perm(ll n,ll r){ if(n < r)return 0; return divmod( fact[n] , fact[n-r]); } ll combi(ll n,ll r){ if(r == 1)return 1; if(n < r || n < 0)return 0; return divmod( perm(n,r) , fact[r]); } ll dupc(ll n,ll r){ if(r == 0)return 1; if(r < 0 || n == 0)return 0; return combi(n+r-1,r); } main(){ fact[0] = 1; rep(i,1,2000010)fact[i] = fact[i-1] * i % MOD; ll T; scanf("%lld",&T); rep(i,0,T){ char c; int a,b; scanf(" %c(%d,%d)",&c ,&a ,&b); ll ans; if(c == 'P')ans = perm(a,b); if(c == 'C')ans = combi(a,b); if(c == 'H')ans = dupc(a,b); cout << ans << endl; } }