#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class RecursiveTournament {
private:
int binpow(int a, int b, int mod) {
int res = 1;
while (b > 0) {
if (b & 1) res = 1LL * res * a % mod;
a = 1LL * a * a % mod;
b >>= 1;
}
return res;
}
public:
int count(vector<string> G, int K) {
int N = G.size();
vector<int> out(N);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (G[i][j] == 'Y') {
out[i] |= 1 << j;
}
}
}
vector<int> dp(1 << N, (1 << N) - 1), pop(1 << N);
for (int i = 0; i < N; ++i) {
for (int j = 1 << i; j < 2 << i; ++j) {
dp[j] &= dp[j - (1 << i)] & out[i];
pop[j] = pop[j - (1 << i)] + 1;
}
}
vector<int> f(1 << N);
for (int i = 1; i < 1 << N; ++i) {
if (dp[i] != 0) {
++f[i | dp[i]];
--f[i];
--f[dp[i]];
}
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 1 << N; ++j) {
if ((j >> i) & 1) {
f[j - (1 << i)] += f[j];
}
}
}
vector<int> tbl(N + 1);
for (int i = 1; i < 1 << N; ++i) {
if (f[i] == 0) {
++tbl[pop[i]];
}
}
const int mod = 998244353; // assuming mod is prime and mod > N
int ans = 0;
for (int i = 1; i <= N; ++i) {
for (int j = 0; j < (i == 1 ? 1 : K); ++j) {
int part1 = binpow(2, binpow(N, j, mod - 1), mod) - 1;
int part2 = binpow(part1, i, mod);
int part3 = binpow(N, K - j - 1, mod);
int part4 = 1LL * part2 * part3 % mod;
ans = (ans + 1LL * part4 * tbl[i]) % mod;
}
}
return ans;
}
};
int main() {
RecursiveTournament solver;
int ans = solver.count({ "NYN", "NNY", "YNN" }, 2);
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjbGFzcyBSZWN1cnNpd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