import sys sys.setrecursionlimit(10 ** 6) def my_pow(x, n, mod): if n == 0: return 1 elif n % 2 == 1: return (x * my_pow((x * x) % mod, n // 2, mod)) % mod else: return my_pow((x * x) % mod, n // 2, mod) mod = 998244353 N = int(input()) all_sum = 0 spring = 0 summer = [0 for _ in range(201)] fall = [0 for _ in range(201)] winter = [0 for _ in range(201)] for i in range(N): S, A = map(str, input().split()) iA = int(A) all_sum += iA if S == 'P': spring += 1 if S == 'U': summer[iA] += 1 if S == 'F': fall[iA] += 1 if S == 'W': winter[iA] += 1 pow_1 = [0 for _ in range(202)] pow_2 = [0 for _ in range(202)] pow_3 = [0 for _ in range(606)] for i in range(201): pow_1[i] = my_pow(N - 1, i, mod) pow_2[i] = my_pow(N - 2, i, mod) for i in range(606): if i <= all_sum: pow_3[i] = my_pow(N - 1, all_sum - i, mod) ans = 0 for i in range(1, 201): for j in range(1, 201): for k in range(1, 201): if summer[i] == 0 or fall[j] == 0 or winter[k] == 0: continue prod = 1 prod = (prod * ((pow_1[i] - pow_2[i] + mod) % mod)) % mod prod = (prod * ((pow_1[j] - pow_2[j] + mod) % mod)) % mod prod = (prod * ((pow_1[k] - pow_2[k] + mod) % mod)) % mod prod = (prod * pow_3[i + j + k]) % mod prod = (prod * summer[i]) % mod prod = (prod * fall[j]) % mod prod = (prod * winter[k]) % mod prod = (prod * spring) % mod ans = (ans + prod) % mod print(ans)