n = int(input()) se = {"U":0,"F":1,"W":2,"P":3} s = [[] for i in range(5)] for i in range(n): si,ai = input().split() s[se[si]].append(int(ai)) mod = 998244353 ans = 1 for i in range(4): cnt = 0 tot = sum(s[i]) for j in s[i]: if i != 3: cnt += (pow(n-1, j, mod) - pow(n-2, j, mod))*pow(n-1, tot-j, mod) else: cnt += pow(n-1, j, mod) *pow(n-1, tot-j, mod) cnt %= mod ans *= cnt ans %= mod print(ans)