#include using namespace std; using ll = long long; template using vec = vector; #define BE(x) x.begin(), x.end() const ll mod = 1000000007; const ll max_n = 2000000; vec inv(max_n+1,1), fact(max_n+1,1), finv(max_n+1,1); bool pre_f = true; void comb_pre () { for (ll i = 2; i <= max_n; i++) { inv [i] = mod-inv[mod%i]*(mod/i)%mod; // inverse for i fact[i] = fact[i-1]*i%mod; // i! finv[i] = finv[i-1]*inv[i]%mod; // inverse for i! } pre_f = false; } ll comb (ll n, ll k) { if (n> q; for (int _ = 0; _ < q; _++) { string s; cin >> s; char c = s[0]; string sn, sk; s.erase(0,2); bool f = false; while (true) { if (!f) { if (s[0] == ',') f = true; else sn += s[0]; s.erase(0,1); } else { if (s[0] == ')') break; sk += s[0]; s.erase(0,1); } } ll n = stoll(sn), k = stoll(sk); ll ans; if (c == 'C') ans = comb(n,k); if (c == 'P') ans = comb(n,k)*fact[k]%mod; if (c == 'H') { if (n == 0 && k == 0) ans = 1; else ans = comb(n+k-1,k); } cout << ans << endl; } }