#define MOD 1000000007 #include #include #include using namespace std; long pow(long a, long b) { if (b == 0) return 1; long c = pow(a, b / 2); if (b % 2) c = a * c % MOD * c % MOD; else c = c * c % MOD; return c; } int main() { int T; scanf("%d%*c", &T); vector a(2000000, 1), b(2000000, 1); for (int i = 1; i < 2000000; i++) { a[i] = a[i - 1] * i % MOD; b[i] = pow(a[i], MOD - 2); } for (int i = 0; i < T; i++) { char c; long N, K; scanf("%c(%ld,%ld)%*c", &c, &N, &K); if (c == 'C') { if (N < K) cout << 0; else cout << a[N] * b[N - K] % MOD * b[K] % MOD; } else if (c == 'P') { if (N < K) cout << 0; else cout << a[N] * b[N - K] % MOD; } else { if (!N) cout << 0; else cout << a[N + K - 1] * b[N - 1] % MOD * b[K] % MOD << endl; } cout << endl; } }