I,R=input,range Q=998244353 N=int(I()) C=[I().split()for n in R(N)] C=[c+[pow(N-1,int(c[1]),Q),1-pow(N-2,int(c[1]),Q)*pow(N-1,-int(c[1]),Q)*(c[0]!="P")]for c in C] S="UFWP" a=1 for c in C:a=a*c[2]%Q for s in S:a=a*sum((s==c[0])*c[3]for c in C)%Q print(a)