#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg char ch=getchar();
	reg int res=0;
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar();
	return res;
}

int main(void){
	reg int a=read(),b=read(),c=read();
	const int mod=4;
	if((b&3)==2)
		if(c==1)
			b=2;
		else
			b=mod;
	else{
		if(!(c&1))
			b=1ll*b*b%mod;
		else
			b%=mod;
		if(!b)
			b=mod;
	}
	a%=10;
	reg int ans=1;
	for(reg int i=1;i<=b;++i)
		ans=1ll*ans*a%10;
	printf("%d\n",ans);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.first << ' ' << p.second << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 998244353
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define NMAX 500005
const long double PI = acos(-1);

int ans = 0, n, mat[55][55], k, mat2[55][55], uz[55], uz2[55], p[55];

bool canSwap(int x, int y, int mat[][55]){
  for (int i=1;i<=n;i++){
    if (mat[i][x] + mat[i][y] > k){
      return false;
    }
  }
  return true;
}

int main(){
  ios::sync_with_stdio(false);
  cin >> n >> k;

  for (int i=1;i<=n;i++){
    uz[i] = uz2[i] = i;
    for (int j=1;j<=n;j++){
      cin >> mat[i][j];
      mat2[j][i] = mat[i][j];
    }
  }

  p[0] = 1;
  for (int i=1;i<=n;i++){
    p[i] = 1LL * i * p[i-1] % MOD;
  }

  dbg(canSwap(1,2,mat));
  ans = 1;
  for (int i=1;i<=n;i++){
    int cnt = 1, cnt2 = 1;
    for (int j=i+1;j<=n;j++){
      if (canSwap(i,j,mat)){
        int sav = uz[j];
        for (int k=1;k<=n;k++){
          if (uz[k] == sav)
            uz[k] = uz[i];
        }
      }
      if (canSwap(i,j,mat2)){
        int sav = uz2[j];
        for (int k=1;k<=n;k++){
          if (uz2[k] == sav)
            uz2[k] = uz2[i];
        }
      }
    }
  }

  for (int i=1;i<=n;i++){
    int cnt = 0, cnt2 = 0;
    for (int j=1;j<=n;j++){
      if (uz[j] == i) cnt++;
      if (uz2[j] == i) cnt2++;
    }

dbg(cnt, cnt2);
    ans = 1LL * ans * p[cnt] % MOD;
    ans = 1LL * ans * p[cnt2] % MOD;
  }

  cout << ans << '\n';
  return 0;
}