#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using db = long double;
using pl = pair<ll, ll>; using vpl = vector<pl>;
using vl = vector<ll>; using vvl = vector<vl>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define FORE(i, a, b) for(ll i=(a); i<=(b); ++i)
#define ROF(i, a, b) for(ll i=(a); i>(b); --i)
#define ROFE(i, a, b) for(ll i=(a); i>=(b); --i)
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define fi first
#define se second
#define _ ios_base::sync_with_stdio(0);cin.tie(0);

#define tpl template
#define tn typename

tpl <tn T>
istream& operator>> (istream& in, vector<T>&v) {
    for(auto &x:v) in>>x;
    return in;
}
tpl <tn T1, tn T2>
ostream& operator<< (ostream& out, const pair<T1,T2>& p) {
    out<<p.fi<<' '<<p.se;
    return out;
}
tpl <tn T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    for(auto x:v) out<<x<<' ';
    return out;
}
tpl <tn T>
ostream& operator<< (ostream& out, const set<T>& st) {
    for(auto x:st) out<<x<<' ';
    return out;
}

tpl <tn T>
T mx(vector<T> A) {
    T ans = 0;
    for(auto x : A) ans = max(ans, x);
    return ans;
}
tpl <tn T>
T mn(vector<T> A) {
    T ans = 0;
    for(auto x : A) ans = min(ans, x);
    return ans;
}
tpl <tn T>
void ps(vector<T> &A){
    partial_sum(all(A), A.begin());
    return;
}
tpl <tn T>
void ad(vector<T> &A){
    adjacent_difference(all(A), A.begin());
    return;
}


ll n, k;
vvl vv;
vl rt;
vl sz;
vl fc;
ll fr(ll x) {return (rt[x]==x ? x : rt[x] = fr(rt[x]));}
void un(ll x, ll y){
    x = fr(x), y = fr(y);
    if(x == y) return;
    if(sz[x] < sz[y]) swap(x, y);
    rt[y] = x;
    sz[x] += sz[y];
}

#define MOD 998244353

bool chv(ll x, ll y){
    FOR(i, 0, n){
        if(vv[i][x] + vv[i][y] > k) return 0;
    }return 1;
}
bool chh(ll x, ll y){
    FOR(i, 0, n){
        if(vv[x][i] + vv[y][i] > k) return 0;
    }return 1;
}

int main(){
    cin >> n >> k;
    vv.rsz(n, vl(n));
    fc.rsz(n+1);
    cin >> vv;
    fc[0] = 1;
    FORE(i, 1, n) fc[i] = fc[i-1] * i % MOD;
    rt.rsz(n + n), sz.rsz(n + n, 1);
    iota(all(rt), 0);
    ll ans = 1;
    FOR(i, 0, n-1) FOR(j, i+1, n){
        if(chv(i, j)) un(i, j);
        if(chh(i, j)) un(i + n, j + n);
    }
    FOR(i, 0, n + n) if(rt[i] == i) ans = ans * fc[sz[i]] % MOD;
    cout << ans;
}
#include <bits/stdc++.h>

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
#define dd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
#define vii vector<ii>
#define vll vector<pll>
#define vdd vector<dd>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvd vector<vd>
#define vvii vector<vii>
#define vvll vector<vll>
#define vvdd vector<vdd>
#define fi first
#define se second
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define prt(v) \
    for (auto& i : v) cout << i << " \n"[&i == &v.back()]

using namespace std;

void print();
template <typename T, typename... Args>
void print(T x, Args... args);

void solve(int T) {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        a[i] = s == "AND";
    }
    vvl dp(n + 1, vl(2, 0));
    dp[0][0] = dp[0][1] = 1;

    for (int i = 0; i < n; ++i) {
        if (a[i]) {
            dp[i + 1][0] = dp[i][0] * 2 + dp[i][1];
            dp[i + 1][1] = dp[i][1];
        } else {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][0] + dp[i][1] * 2;
        }
    }

    cout << dp[n][1] << '\n';
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 0; i++ < t;) solve(i);

    return 0;
}

void print() { cout << "\n"; }
template <typename T, typename... Args>
void print(T x, Args... args) {
    if (sizeof...(args)) {
        cout << x << ' ';
        print(args...);
    } else {
        cout << x << '\n';
    }
}