#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=998244353,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

int p[200001],r[200001];
void init(){rep(i,200001)p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n][n];
  rep(i,n)rep(j,n) R a[i][j];
  ll d[n+1];
  mem(d);
  d[0]=1;
  REP(i,1,n+1) d[i]=d[i-1]*i%MAX;
  init();
  rep(i,n) {
    REP(j,i+1,n) {
      ll f1=1,f2=1;
      rep(k,n) {
        if(a[k][i]+a[k][j]>m) f1=0;
        if(a[i][k]+a[j][k]>m) f2=0;
      }
      if(f1) unite(i,j);
      if(f2) unite(i+n,j+n);
    }
  }
  ll x[n],y[n];
  mem(x);mem(y);
  rep(i,n) {
    x[find(i)]++;
    y[find(i+n)-n]++;
  }
  ll d1=1,d2=1;
  rep(i,n) {
    d1*=d[x[i]];
    d1%=MAX;
    d2*=d[y[i]];
    d2%=MAX;
  }
  pr(d1*d2%MAX);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

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

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn=110;

int n,m;
bool ans[maxn][maxn];
vector <int> edge[maxn];
pii e[maxn*maxn];
int c[maxn];
bool vis[maxn];

void dfs(int u) {
	vis[u]=true;
	for(int v:edge[u]) {
		if (ans[u][v]||ans[v][u]) continue;
		ans[u][v]=true;
		if (!vis[v])dfs(v);
	}
}

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie();
	cin>>n>>m;
	rep(i,0,m) cin>>e[i].fi>>e[i].se;
	rep(i,1,n+1) cin>>c[i];
	memset(ans,0,sizeof(ans));
	rep(i,0,m) {
		if (c[e[i].fi]==c[e[i].se]) edge[e[i].fi].pb(e[i].se),edge[e[i].se].pb(e[i].fi);
		else if (c[e[i].fi]>c[e[i].se]) ans[e[i].fi][e[i].se]=true;
		else ans[e[i].se][e[i].fi]=true;
	}
	rep(i,1,n+1) dfs(i);
	rep(i,0,m) {
		if (ans[e[i].fi][e[i].se]) cout<<"->\n";
		else cout<<"<-\n";
	}
	return 0;
}
