using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var s = SList(n); var doors = new List[4]; for (var i = 0; i < doors.Length; ++i) doors[i] = new List(); for (var i = 0; i < s.Length; ++i) { var a = int.Parse(s[i].Split()[1]); if (s[i][0] == 'U') doors[0].Add(a); else if (s[i][0] == 'F') doors[1].Add(a); else if (s[i][0] == 'W') doors[2].Add(a); else doors[3].Add(a); } foreach (var d in doors) if (d.Count == 0) { WriteLine(0); return; } var mod = 998_244_353; var ans = 1L; for (var i = 0; i < doors.Length; ++i) { var sum = 0L; var count = 0L; foreach (var d in doors[i]) count += d; var all = Exp(n - 1, count, mod); if (i + 1 < doors.Length) { foreach (var a in doors[i]) { sum = (sum + (Exp(n - 1, a, mod) - Exp(n - 2, a, mod) + mod) % mod * Exp(n - 1, count - a, mod) % mod) % mod; // sum = (sum + all + mod - Exp(n - 2, a, mod)) % mod; // WriteLine($"add ({Exp(n - 1, a, mod)} - {Exp(n - 2, a, mod)}) * {Exp(n - 1, count - a, mod)}"); } // sum = sum * doors[i + 1].Count % mod; } else { foreach (var a in doors[i]) sum = (sum + all) % mod; } // WriteLine($"{i} {sum}"); ans = ans * sum % mod; } WriteLine(ans); } static long Exp(long n, long k, int mod) { if (k == 0) return 1; if (k == 1) return n % mod; var half = Exp(n, k / 2, mod); var result = (half * half) % mod; return ((k % 2) == 0) ? result : ((result * n) % mod); } }