#include using namespace std; #define INF 1.1e9 #define LINF 1.1e18 #define FOR(i,a,b) for (int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define pb push_back #define pf push_front #define fi first #define se second #define BIT(x,n) bitset(x) #define PI 3.14159265358979323846 typedef long long ll; typedef pair P; typedef pair PP; //----------------------------------------------------------------------------- template struct Combination { vector fc,ifc; T MOD; int sz; Combination(T MOD,T sz):fc(sz+1),ifc(sz+1),MOD(MOD),sz(sz) {} void init() { fc[0]=1; for(int i=1;i<=sz;i++) fc[i]=fc[i-1]*i%MOD; ifc[sz]=inv(fc[sz]); for(int i=sz-1;i>=0;i--) ifc[i]=ifc[i+1]*(i+1)%MOD; } // 階乗 T fact(int n) { return fc[n]; } // 階乗の逆元 T inv_fact(int n) { return ifc[n]; } //逆元 T inv(int n) { return pow(n,MOD-2); } // 冪乗 T pow(T n,int a) { T res=1; while(a>0) { if(a&1) (res*=n)%=MOD; (n*=n)%=MOD; a>>=1; } return res; } // 順列 T perm(T n,T r) { if(r<0||n>t; Combination C((int)1e9+7,(int)1e6*2+10); C.init(); while(t--) { char ch[10];ll n,k; scanf("%1s(%lld,%lld)",ch,&n,&k); if(ch[0]=='C') printf("%lld\n",C.comb(n,k)); else if(ch[0]=='P') printf("%lld\n",C.perm(n,k)); else printf("%lld\n",C.multi_comb(n,k)); } }