#include<bits/stdc++.h>
using namespace std;
#define ll long long
int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while('0'<=c&&c<='9'){
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return x*f;
}
const int N=1000+10,mod=998244353;
int T,id;
int n,m,c,f;
int p[N][N];
ll ansc=0,ansf=0;
void putin(){
//	memset(p,0,sizeof(p));
	n=read();m=read();c=read();f=read();
	string s;
	for(int i=1;i<=n;i++){
		cin>>s;
		for(int j=1;j<=m;j++){
			p[i][j]=s[j-1]-'0';
		}
	}
	ansc=0;ansf=0;
}
namespace Sub1{
	void mian(){
		printf("0 0\n");
		return;
	}
}
namespace Sub2{
	int f[N][N];
	void pre(){
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
				f[i][j]=-1;					
		for(int i=1;i<=n;i++){
			int cnt=0;
			for(int j=m;j>=1;j--){
				if(p[i][j]==0){
					f[i][j]=cnt++;
				}else{
					f[i][j]=-1;
					cnt=0;
				}
			}
		}
	}
	ll calc(int ke,int l,int r){
		ll res=0;
		for(int i=l;i<r;i++){
			for(int j=i+2;j<r;j++){
				res=(res+f[i][ke]*f[j][ke])%mod;
			}
		}
		return res;
	}
	ll falc(int ke,int l,int r){
		ll res=0;
		for(int i=l;i<r;i++){
			for(int j=i+2;j<r;j++){
				int tlen=r-j-1;
				res=(res+tlen*f[i][ke]*f[j][ke])%mod;
			}
		}
		return res;
	}
	void mian(){
		pre();
		for(int i=1;i<=m;i++){
			int l=0,r=1;
			while(true){
				while(f[l][i]==-1&&l<=n) l++;
				if(l>n) break;
				r=l;
				while(f[r][i]!=-1&&r<=n) r++;
				//[l,r)
				ansc=(ansc+calc(i,l,r))%mod;
				ansf=(ansf+falc(i,l,r))%mod;
				l=r;
			}
		}
		printf("%lld %lld\n",ansc,ansf);
		return;
	}
}
namespace Sub3{
	int f[N][N];
	void pre(){
		for(int i=0;i<=n;i++)
			for(int j=0;j<=m;j++)
				f[i][j]=-1;					
		for(int i=1;i<=n;i++){
			int cnt=0;
			for(int j=m;j>=1;j--){
				if(p[i][j]==0){
					f[i][j]=cnt++;
				}else{
					f[i][j]=-1;
					cnt=0;
				}
			}
		}
	}
	ll calc(int ke,int l,int r){
		ll res=0;
		for(int i=l;i<r;i++){
			for(int j=i+2;j<r;j++){
				res=(res+f[i][ke]*f[j][ke])%mod;
			}
		}
		return res;
	}
	void mian(){
		pre();
		for(int i=1;i<=m;i++){
			int l=0,r=1;
			while(true){
				while(f[l][i]==-1&&l<=n) l++;
				if(l>n) break;
				r=l;
				while(f[r][i]!=-1&&r<=n) r++;
				//[l,r)
				ansc=(ansc+calc(i,l,r))%mod;
				l=r;
			}
		}
		printf("%lld 0\n",ansc);
		return;
	}
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read();id=read();
	while(T--){
		putin();
		if(id==1) Sub1 :: mian();else
		if(2<=id&&id<=14) Sub2 :: mian();else
		if(id==15) Sub3 :: mian();else
		if(id==16) Sub2 :: mian();
	}		
	return 0;
}
