/* 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 */ using namespace std; //#define int long long /* typedef */ typedef long long ll; typedef long double ld; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vl; typedef vector vst; typedef vector vb; typedef vector vld; typedef vector vpii; typedef vector vpll; typedef vector > vvi; /* const */ const int INF = 1e9; const int MOD = 1e9 + 7; const double PI = acos(-1.0); const double EPS = 1e-9; const ll INFF = 1e18; const ll INTMAX = (0x7FFFFFFFL); const ll LLMAX = (0x7FFFFFFFFFFFFFFFL); int dx[9] = { 1, 0, -1, 0, 1, -1, -1, 1, 0 }; int dy[9] = { 0, 1, 0, -1, -1, -1, 1, 1, 0 }; /* input */ #define S(s) cin >> (s); #define SS(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template void MACRO_VAR_Scan(T& t){cin >> t;} template void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);} #define SV(type,c,n) vector c(n);for(auto& i:c)cin >> i; #define SVV(type,c,n,m) vector> c(n,vector(m));for(auto& r:c)for(auto& i:r)cin >> i; /* output */ #define print(p) cout << (p) << endl; template void PA(T &a){int ASIZE=sizeof(a)/sizeof(a[0]);for(int ii=0;ii void PV(T &v){int VSIZE=v.size();for(int ii=0;ii=int(b);--i) #define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__) #define EACH(e,v) for(auto& e : v) #define PERM(v) sort((v).begin(),(v).end());for(bool c##p=1;c##p;c##p=next_permutation((v).begin(),(v).end())) /* calculation */ inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline ll lcm(ll a,ll b){return a*b/gcd(a,b);} inline ll POW(ll a,ll b){ll c=1ll;do{if(b&1)c*=1ll*a;a*=1ll*a;}while(b>>=1);return c;} inline ll bit(ll x){return (1ll << x);} inline bool isPrime(int x){ if(x<2) return false; if(x==2) return true; if(x%2==0) return false; for(int i=3;i<=sqrt(x)+1;i+=2) if(x%i==0) return false; return true; } inline vb Eratosthenes(const int n) { // ~10^6: Eratosthenes vb r(n+1,true); // 10^7~: Simple for(int i=2;i*i<=n;++i){ if(r[i]){ for(int j=i*2;j<=n;j+=i)r[j]=false; } } if(r.size()>2){r[0]=0;r[1]=0;} else if(r.size()>1){r[0]=0;} return r; // [0,n) } template inline bool between(T x,T a,T b) {return ((a<=x)&&(x inline T sqr(T x){return x*x;} template inline bool chmax(A &a,const B &b){if(a inline bool chmin(A &a,const B &b){if(a>b){a=b;return 1;}return 0;} #define tmax(x,y,z) max((x),max((y),(z))) #define tmin(x,y,z) min((x),min((y),(z))) inline ll digitsum(ll x){ll d;ll r=0;while(x){d=x%10;r+=d;x/=10;}return r;} /* modulo */ #define ADD(a,b) a=(a+ll(b))%MOD #define MUL(a,b) a=(a*ll(b))%MOD ll MOP(ll a,ll b,ll mod=1e9+7) {ll c=1ll;do{if(b&1)c*=1ll*a%mod;a*=1ll*a%mod;}while(b>>=1);return c;} // Combination // NUM_: max of n for nCr const int NUM_=2000000; ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1]; void COMinit(ll mo=MOD) { int i; inv[1]=fact[0]=factr[0]=1; for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo; for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo; } ll nCr(ll N_, ll C_, ll mo=MOD) { if (C_<0 || C_>N_) return 0; else return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo; } ll nPr(ll N_, ll C_, ll mo=MOD) { if (C_<0 || C_>N_) return 0; else return fact[N_]*factr[N_-C_]; } ll nHr(int P_, int Q_, ll mo=MOD) { if (P_==0 && Q_==0) return 1; else return nCr(P_+Q_-1,Q_)%mo; } /* conversion */ inline ll toInt(string s){ll v;istringstream sin(s);sin >> v;return v;} template inline string toString(T x) {ostringstream sout;sout << x;return sout.str();} template inline void ntos(const T &n,string &s){stringstream stream; stream << n; stream >> s;} template inline void ston(const string &s,T &n){stringstream stream(s); stream >> n;} /* container */ #define fst first #define snd second #define PB push_back #define MP make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define SORT(v) sort((v).begin(),(v).end()) #define RSORT(v) sort((v).rbegin(),(v).rend()) #define EXIST(s,e) (find((s).begin(),(s).end(),(e))!=(s).end()) #define EXISTST(s,c) (((s).find(c))!=string::npos) #define POSL(x,val) (lower_bound(x.begin(),x.end(),val)-x.begin()) #define POSU(x,val) (upper_bound(x.begin(),x.end(),val)-x.begin()) #define SZV(a) int((a).size()) #define SZA(a) sizeof(a)/sizeof(a[0]) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MEMINF(a) memset(a,0x3f,sizeof(a)) #define FILL(a,b) memset(a,b,sizeof(a)) #define UNIQUE(v) sort((v).begin(),(v).end());(v).erase(unique((v).begin(),(v).end()),(v).end()) bool SORT_PAIR_SECOND(const pii& a,const pii& b){return a.second parent; int __size; UnionFind(int size_) : parent(size_, -1), __size(size_) {} void unite(int x,int y) { if ((x=find(x)) != (y=find(y))) { if (parent[y] < parent[x]) swap(x,y); parent[x] += parent[y]; parent[y] = x; __size--; } } bool same(int x,int y){return find(x)==find(y);} int find(int x){return parent[x] < 0 ? x : parent[x] = find(parent[x]);} int size(int x){return -parent[find(x)];} int size(){return __size;} }; /* graph */ using Weight = int; // !!!OVERFLOW!!! using Flow = int; struct Edge { int src, dst; Weight weight; Flow cap; Edge() : src(0), dst(0), weight(0) {} Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {} }; using Edges = vector; using Graph = vector; using Array = vector; using Matrix = vector; void add_edge(Graph &g,int a,int b,Weight w=1){g[a].emplace_back(a,b,w);g[b].emplace_back(b,a,w);} void add_arc(Graph &g,int a,int b,Weight w=1){g[a].emplace_back(a,b,w);} Matrix WarshallFloyd(const Graph &g) { auto const INF = std::numeric_limits::max()/8; int n = g.size(); Matrix d(n,Array(n,INF)); REP(i,n) d[i][i] = 0; REP(i,n) for(auto &e : g[i]) d[e.src][e.dst]=min(d[e.src][e.dst],e.weight); REP(k,n) REP(i,n) REP(j,n) if(d[i][k]!=INF && d[k][j]!=INF) d[i][j]=min(d[i][j],d[i][k]+d[k][j]); return d; } vector Dijkstra(const Graph &g,int s) { const Weight INF = numeric_limits::max()/8; using state = tuple; priority_queue q; vector dist(g.size(),INF); dist[s] = 0; q.emplace(0,s); while (q.size()) { Weight d; int v; tie(d,v) = q.top(); q.pop(); d *= -1; /* if(v == t) return d; */ if (dist[v] dist[v] + e.weight) { dist[e.dst] = dist[v] + e.weight; q.emplace(-dist[e.dst], e.dst); } } } return dist; } /* abracadabra */ struct abracadabra{ abracadabra(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } ABRACADABRA; //---------------8<---------------8<---------------8<---------------8<---------------// signed main() { char s[2]; int a,b; COMinit(); SS(int,T); REP(i,T) { scnaf("%1s(%d,%d)", s, &a, &b); switch(s[0]) { case 'C': print(nCr(a,b)); break; case 'P': print(nPr(a,b)); break; case 'H': print(nHr(a,b)); break; } } }