#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MEM(a,b) memset((a),(b),sizeof(a)) const LL INF = 1e9 + 7; const int N = 2e3 + 10; const LL mod = 998244353; LL powmod(LL a, LL b) { a %= mod; LL ret = 1; while (b) { if (b & 1) ret = ret * a % mod; b >>= 1; a = a * a % mod; } return ret; } vector v[4]; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); LL cnt[4] = { 0,0,0,0 }; LL tot[4] = { 0,0,0,0 }; map mc; mc['U'] = 0; mc['F'] = 1; mc['W'] = 2; mc['P'] = 3; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char c; int d; scanf(" %c%d", &c, &d); cnt[mc[c]]++; tot[mc[c]] += d; v[mc[c]].push_back(d); } if (tot[0] == 0 || tot[1] == 0 || tot[2] == 0) { puts("0"); return 0; } // (x^ a - (x - 1) ^ a) + (n - 1) ^ rest LL ans = 1; for (int i = 0; i < 3; i++) { LL sum = 0; for (auto& d : v[i]) { sum += (powmod(n - 1, d) - powmod(n - 2, d)) % mod * powmod(n - 1, tot[i] - d) % mod; } sum %= mod; ans = ans * sum % mod; } ans = ans * powmod(n - 1, tot[3]) % mod; if (ans < 0) ans += mod; ans = ans * cnt[0] % mod; printf("%lld\n", ans); return 0; }