#include #define fi first #define se second #define eb emplace_back #define mp make_pair using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef __int128 i128; template T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);} template T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);} template bool chmax(T &a,const S b) {return (a bool chmin(T &a,const S b) {return (a>b?a=b,1:0);} int popcnt(int x) {return __builtin_popcount(x);} int popcnt(ll x) {return __builtin_popcountll(x);} int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));} int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));} int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));} int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));} #define int long long #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) typedef pair pii; typedef vector vi; typedef vector vp; int read() { int x=0,w=1; char c=getchar(); while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();} while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} return x*w; } const int N=3e5+5,mod=998244353; int n,s[N],a[N],ans; char t[2]; vi f[4]; int convert(char x) { if(x=='U') return 0; else if(x=='F') return 1; else if(x=='W') return 2; else return 3; } int ksm(int x,int y,int r=1) { for(;y;y>>=1,x=x*x%mod) if(y&1) r=r*x%mod; return r; } signed main() { n=read(); ans=1; rep(i,1,n) { scanf("%s%lld",t,&a[i]); s[i]=convert(t[0]); f[s[i]].eb(a[i]); } ans=f[3].size(); for(int a:f[3]) ans=ans*ksm(n-1,a)%mod; rep(i,0,2) { int res=0; for(int a:f[i]) { int w=ksm(n-2,a)*ksm(ksm(n-1,a),mod-2)%mod; res=(res+1+mod-w)%mod; } for(int a:f[i]) res=res*ksm(n-1,a)%mod; ans=ans*res%mod; } printf("%lld\n",ans); return 0; }