#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; #define rep(i,n) for(ll i=0;i<(n);i++) #define tii tuple #define tiii tuple #define mt make_tuple #define pb push_back #define ALL(a) (a).begin(),(a).end() #define FST first #define SEC second const int INF = (INT_MAX/2); const ll LLINF = (LLONG_MAX/2); const double eps = 1e-5; const double PI = M_PI; #define DEB cerr<<"!"<0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;} class FermatCombination{ public: vector factrial; // ιšŽδΉ— vector inverse; // 逆元 FermatCombination(int size){ factrial.resize(size+1); inverse.resize(size+1); factrial[0] = 1; inverse[0] = 1; for(int i = 1; i < size+1; i++){ factrial[i] = factrial[i-1] * i % DIV; inverse[i] = pow(factrial[i],DIV-2,DIV); } } ll combination(int n, int k){ return factrial[n]* inverse[k] % DIV * inverse[n - k] % DIV; } ll permutation(int n, int k){ return factrial[n] * inverse[n-k] % DIV; } ll multi_choose(int n, int k){ if(n == 0 && k == 0) return 1; else return combination(n+k-1,k); } }; int to1(string s){ string ret =""; for(int i = 2; s[i] != ','; i++) ret = ret + s[i]; return stoi(ret); } int to2(string s){ string ret =""; for(int i = s.size()-2; s[i] != ','; i--) ret = s[i] + ret; return stoi(ret); } int main(){ int n; cin >> n; FermatCombination FC(200000); rep(i,n){ string s; cin >> s; ll ans = 0; if(s[0] == 'C'){ ans = FC.combination(to1(s),to2(s)); }else if(s[0] == 'P'){ ans = FC.permutation(to1(s),to2(s)); }else{ ans = FC.multi_choose(to1(s),to2(s)); } cout << ans << endl; } }