#include #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(obj) obj.begin(), obj.end() const int iINF = 1e9; const long long llINF = 1e18; const int MOD = 1e9 + 7; using namespace std; const int MAX = 1000000; vector fac(MAX + 1), inverseFac(MAX + 1); long long modPow(long long x, long long n) { long long ans = 1; while (n != 0) { if (n & 1) ans = ans * x % MOD; x = x * x % MOD; n = n >> 1; } return ans; } long long comb(long long a, long long b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; long long tmp = inverseFac[a - b] * inverseFac[b] % MOD; return tmp * fac[a] % MOD; } long long perm(long long a, long long b) { if (a < b) return 0; long long tmp = inverseFac[a - b] % MOD; return tmp * fac[a] % MOD; } long long dupc(long long a, long long b) { if (a == 0 && b == 0) return 1; if (a < 0 || b == 0) return 0; long long tmp = inverseFac[a - 1] * inverseFac[b] % MOD; return tmp * fac[a + b - 1] % MOD; } void init() { fac[0] = 1; inverseFac[0] = 1; for (long long i = 0; i < MAX; i++) { fac[i + 1] = fac[i] * (i + 1) % MOD; inverseFac[i + 1] = inverseFac[i] * modPow(i + 1, MOD - 2) % MOD; } } int main() { init(); int t; cin >> t; char com, n1, n2, n3; int n, k; REP(i, t) { cin >> com >> n1 >> n >> n2 >> k >> n3; if (com == 'C') { cout << comb(n, k) << endl; } else if (com == 'P') { cout << perm(n, k) << endl; } else { cout << dupc(n, k) << endl; } } }