#include #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR(i, init, n) for (int i = init; i < (n); i++) #define ALL(obj) (obj).begin(), (obj).end() #define fi first #define se second using namespace std; using ll = long long int; using P = pair; using T = tuple; using edge = struct { int to, cost; }; const int MOD = 1e9 + 7; const int iINF = 1e9; const long long int llINF = 1e18; const double PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int MAX = 1000010; vector fac(MAX), ifac(MAX); ll mpow(ll x, ll n) { ll ans = 1; while (n > 0) { if (n & 1) ans = ans * x % MOD; x = x * x % MOD; n = n >> 1; } return ans; } ll perm(ll n, ll k) { if(n < k) return 0; return (fac[n] * ifac[n - k]) % MOD; } ll dupc(ll n, ll k) { if (n == 0 && k == 0) return 1; if (n < 0 || k == 0) return 0; return ((fac[n + k - 1] * ifac[k]) % MOD * ifac[n - 1]) % MOD; } ll comb(ll n, ll k) { if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return ((fac[n] * ifac[k]) % MOD * ifac[n - k]) % MOD; } int main() { cin.tie(0); ios::sync_with_stdio(false); fac[0] = 1; ifac[0] = 1; REP(i, MAX) { fac[i + 1] = fac[i] * (i + 1) % MOD; ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD; } int T; cin >> T; vector coms(T); vector N(T), K(T); char a, b, c, d, e; REP(i, T) cin >> coms[i] >> a >> N[i] >> b >> K[i] >> c; REP(i, T) { int ans = 0; if(coms[i] == 'P') ans = perm(N[i], K[i]); else if(coms[i] == 'C') ans = comb(N[i], K[i]); else ans = dupc(N[i], K[i]); cout << ans << endl; } return 0; }