#include using namespace std; typedef long long ll; typedef pair l_l; typedef pair i_i; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) const ll mod = 1000000007; ll inv[10000100]; ll FactorialInv[10000100]; ll Factorial[10000100]; ll beki(ll a, ll b){ if(b == 0){ return 1; } ll ans = beki(a, b / 2); ans = ans * ans % mod; if(b % 2 == 1){ ans = ans * a % mod; } return ans; } void init_combination(){ const int MAX = 2000002; Factorial[0] = 1; inv[0] = 1; for(int i = 1; i <= MAX; i++){ Factorial[i] = Factorial[i - 1] * i % mod; } FactorialInv[MAX] = beki(Factorial[MAX], mod - 2); for(ll i = MAX - 1; i >= 0; i--) { FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod; } for(int i = 1; i <= MAX; i++) { inv[i] = FactorialInv[i] * Factorial[i-1] % mod; } } ll combination(ll a, ll b){ if((a == b) || (b == 0)){ return 1; } if(a < b) return 0; ll ans = Factorial[a] * FactorialInv[b] % mod; ans = ans * FactorialInv[a - b] % mod; return ans; } void C(ll n, ll k) { cout << combination(n, k) << "\n"; } void P(ll n, ll k) { cout << combination(n, k) * Factorial[k] % mod << "\n"; } void H(ll n, ll k) { cout << combination(n + k - 1, k) << "\n"; } void solve() { char in; cin >> in; char dust; cin >> dust; ll n, k; cin >> n >> dust >> k >> dust; if(in == 'C') C(n, k); if(in == 'P') P(n, k); if(in == 'H') H(n, k); } int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); init_combination(); ll T; cin >> T; while(T--) solve(); return 0; }