#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
 
#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
 
const int MAX = 55 * 55;
const int MOD = 998244353;
int fat[MAX];
 
inline int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}
 
inline int sub(int a, int b) {
    a -= b;
    if (0 > a) a += MOD;
    return a;
}
 
inline int mult(int a, int b) {
    return (1LL * a * b) % MOD;
}
 
int f_exp(int x, int e) {
    if (e <= 0) return 1;
    if (e & 1) return mult(x, f_exp(x, e - 1));
    return f_exp(mult(x, x), e / 2);
}
 
inline int inv(int x) {
    return f_exp(x, MOD - 2);
}
 
inline int comb(int n, int k) {
    if (k > n) return 0;
    return mult(fat[n], mult(inv(fat[n - k]), inv(fat[k])));
}
 
void preprocess() {
    fat[0] = 1;
    fori (i, 1, MAX) {
        fat[i] = mult(fat[i - 1], i);
    }
}
 
int row_max[MAX];
int col_max[MAX];
vector<int> adj[2][MAX];
bool visited[2][MAX];
int n, k;
int mat[55][55];

int bfs(int id, int start) {
    queue<int> q;
    q.push(start);
    visited[id][start] = true;
    
    int size = 0;

    while (!q.empty()) {
        int cur = q.front();
        q.pop();

        size++;

        for (auto &each : adj[id][cur]) {
            if (!visited[id][each]) {
                visited[id][each] = true;
                q.push(each);
            }
        }
    }

    return size;
}

void solve() {
    preprocess();
    
    cin >> n >> k;
    fori (i, 1, n + 1) {
        fori (j, 1, n + 1) {
            cin >> mat[i][j];
            row_max[i] = max(row_max[i], mat[i][j]);
            col_max[j] = max(col_max[j], mat[i][j]);
        }
    }

    fori (i, 1, n + 1) {
        fori (j, i + 1, n + 1) {
            bool row_ok = true;
            bool col_ok = true;
            fori (f, 1, n + 1) {
                if (mat[i][f] + mat[j][f] > k) row_ok = false; 
                if (mat[f][i] + mat[f][j] > k) col_ok = false; 
            }

            if (row_ok) {
                adj[0][i].push_back(j);
                adj[0][j].push_back(i);
            }

            if (col_ok) {
                adj[1][i].push_back(j);
                adj[1][j].push_back(i);
            }
        }
    }

    int prod[2];
    prod[0] = prod[1] = 1;

    fori (i, 0, 2) {
        fori (j, 1, n + 1) {
            if (!visited[i][j]) {
                int size = bfs(i, j);
                prod[i] = mult(prod[i], fat[size]);
            }
        }
    }

    cout << mult(prod[0], prod[1]) << endl;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}

// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &bb) {
    for (int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &bb) {
    for (int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}

using namespace std;

ll dp[110][130000];

int main() {
    ll n, k, m; cin >> n >> k >> m;
    dp[0][0] = 1;
    rip(i,n+1,1) {
        rip(j,130000, 0) {
            dp[i][j] = dp[i-1][j];
            
            if(j-i >= 0) {
                dp[i][j] += dp[i][j-i];
                dp[i][j] %= m;
            }
            if(j - i*(k+1) >= 0) {
                dp[i][j] -= dp[i-1][j - i*(k+1)]+m;
                dp[i][j] %= m;
            }
        }
    }
    rip(i, n, 0) {
        ll ans = 0;
        rip(j, 130000, 0) {
            ans += 1LL * dp[i][j] * dp[n-i-1][j] % m;
        }
        printf("%lld\n", (ans%m*(k+1)%m-1+m)%m);
    }
}
