#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int N; cin>>N; vector x(N),y(N); rep(i,N){ char c; cin>>c; if(c=='U')x[i] = 0; if(c=='F')x[i] = 1; if(c=='W')x[i] = 2; if(c=='P')x[i] = 3; cin>>y[i]; } vector dp(1<<4,0); dp[0] = 1; rep(i,N){ vector ndp(1<<4); mint A = mint(N-1).pow(y[i]); mint B = mint(N-1).pow(y[i]) - mint(N-2).pow(y[i]); rep(j,1<<4){ ndp[j] += dp[j] * A; if((j>>x[i])&1)continue; if(x[i]!=3)ndp[j|(1<