#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* PascalCase クラス名 camelCase メソッド名,関数名,変数名 snake_case ファイル名,名前空間,std のメソッド名,変数名,型名に準じる場合 SNAKE_CASE マクロ名,static const 定数,列挙体 */ #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 RALL(obj) (obj).rbegin(), (obj).rend() #define Cout(obj) cout << obj << endl #define Size(obj) (int)(obj).size() #define fcout cout << fixed << setprecision(10) #define fi first #define se second using namespace std; using lint = long long int; using vvlint = vector>; using vlint = vector; using vvint = vector>; using vint = vector; 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 = 3000000; vector fac(MAX + 1); vector modFac(MAX + 1); lint powMod(lint n, lint p) { lint ans = 1; while (p != 0) { if (p & 1) ans = ans * n % MOD; n = n * n % MOD; p = p >> 1; } return ans; } lint comb(lint n, lint r) { if(r < 0 || r > n) return 0; return (fac[n] * modFac[r]) % MOD * modFac[n - r] % MOD; } lint dupc(lint n, lint r) { if (n == 0 && r == 0) return 1; return comb(n + r - 1, r) % MOD; } lint perm(lint n, lint r) { if(r < 0 || r > n) return 0; return (fac[n] * modFac[n - r]) % MOD; } int main() { cin.tie(0); ios::sync_with_stdio(false); fac[0] = 1; modFac[0] = 1; REP(i, MAX) { fac[i + 1] = (fac[i] * (i + 1)) % MOD; modFac[i + 1] = modFac[i] * powMod(i + 1, MOD - 2) % MOD; } int T; cin >> T; vector com(T); vector N(T), K(T); REP(i, T) { scanf(" %c(%d,%d)", &com[i], &N[i], &K[i]); } REP(i, T) { if(com[i] == 'C') { cout << comb(N[i], K[i]); } else if(com[i] == 'P') { cout << perm(N[i], K[i]); } else { cout << dupc(N[i], K[i]); } cout << endl; } return 0; }