#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define show(x) cout <<#x<<" = "<<(x)<P; const int MAX_N = 2000001; //どこかでmake()することを忘れずに ll inv[MAX_N],fac[MAX_N],finv[MAX_N]; void make() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i=2;i> n; make(); rep(i,n){ char c[20]; scanf("%s",c); int st=2; string s1,s2; while(1){ if(!isdigit(c[st])){ break; }else{ s1.pb(c[st]); } st++; } st++; while(1){ if(!isdigit(c[st])){ break; }else{ s2.pb(c[st]); } st++; } int u = stoi(s1),v = stoi(s2); if(c[0] == 'C'){ cout << comb(u,v) << endl; }else if(c[0] == 'P'){ if(u - v < 0){ cout << "0\n"; }else{ cout << fac[u] * finv[u-v] << endl; } }else{ if(u == 0 && v == 0){ cout << "1\n"; }else{ cout << comb(u+v-1,v) << endl; } } } return 0; }