#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(n < r)return 0; return divmod( perm(n,r) , fact[r]); } ll dupc(ll n,ll r){ return combi(n+r-1,r); } main(){ fact[0] = 1; rep(i,1,2000010)fact[i] = fact[i-1] * i % MOD; ll T; cin >> T; rep(i,0,T){ string S,str[2] = {}; cin >> S; char p = S[0]; bool f = 0; for(char c:S){ if(c == ',')f = 1; if(c >= '0' && c <= '9')str[f].push_back(c); } ll ans; if(p == 'P')ans = perm( stoi(str[0]),stoi(str[1]) ); if(p == 'C')ans = combi( stoi(str[0]),stoi(str[1]) ); if(p == 'H')ans = dupc( stoi(str[0]),stoi(str[1]) ); cout << ans << endl; } }