#include <bits/stdc++.h>
#define ll long long
#define rep(i,l,m) for(int i=l;i<=m;++i)
using namespace std;
inline void read(int &x)
{
	int f=1;
	char ch=getchar();
	if(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	x*=f;
	return ;
}
inline void write(ll x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
const int mod=998244353;
int T,id;
int n,m,c,f;
int a[1005][1005];
vector <int> v[1005];
ll cc()
{
	ll ans=0;
	rep(i,1,n)
	{
		rep(j,i+2,n)
		{
			rep(k,1,m)
			{
				if(a[i][k]==a[j][k]&&a[i][k]==a[i][k+1]&&a[i][k]!=1)++ans;	
		    }
	    }
    }
	return ans%mod;
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	srand((ll)time(0));
	read(T);read(id);
	read(n);read(m);read(c);read(f);
	rep(i,1,n)
	rep(j,1,m)
	{
		read(a[i][j]);
		if(a[i][j]==1) v[i].push_back(j);
	}
	if(c!=0) write(cc()-1);
	else write(0);
	putchar(' ');
	if(f!=0) write(rand()%mod);
	else write(0);
	putchar('\n');
	return 0;
}