#include<bits/stdc++.h>
using namespace std;
const long long q=998244353;
const int maxn=1e+3;
int n,t,m,id,c,f;
int ff[maxn+50][maxn+50];
int ans[maxn+50][maxn+50];
void inti(){
	for(int i=1;i<=n;i++){
		int ans1=0;
		for(int j=m;j>=1;j--){
			if(ff[i][j]==1)ans1=0;
			else ans1++;
			ans[i][j]=ans1;
		}
	}
}
bool check(int x1,int x2,int y){
	for(int i=x1;i<=x2;i++){
		if(ff[i][y]==1)return true;
	}
	return false;
}
long long workc(){
	long long ans1=0;
	for(int x1=1;x1<=n;x1++){
		if(ff[x1][0]<2)continue;
		for(int y=1;y<=m;y++){
			if(ans[x1][y]<=1)continue;
			for(int x2=x1+2;x2<=n;x2++){
				if(ans[x2][y]<=1)continue;
				if(check(x1,x2,y))break;
				ans1=(((((ans[x1][y]-1)%q)*((ans[x2][y]-1)%q))%q)+ans1%q)%q;
			}
		}
	}
	return ans1;
}
long long workf(){
	long long ans1=0;
	for(int x1=1;x1<=n;x1++){
		if(ff[x1][0]<2)continue;
		for(int y=1;y<=m;y++){
			if(ans[x1][y]<=1)continue;
			for(int x2=x1+2;x2<=n;x2++){
				if(ans[x2][y]<=1)continue;
				if(check(x1,x2,y))break;
				for(int x3=x2+1;x3<=n;x3++){
					if(ans[x3][y]==0)continue;
					if(check(x2,x3,y))break;
					ans1=(((((ans[x1][y]-1)%q)*((ans[x2][y]-1)%q))%q)+ans1%q)%q;
				}
			}
		}
	}
	
	return ans1;
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&t,&id);
	while(t){
		scanf("%d%d%d%d",&n,&m,&c,&f);
		if(c==0&&f==0){
			cout<<"0 0"<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++){
			char a;
			for(int j=1;j<=m;j++){
				cin>>a;
				ff[i][j]=a-'0';
				if(ff[i][j]==0)ff[i][0]++;
			}
		}
		inti();
		long long a=workc()%q;
		if(f==0)cout<<a;
		else {
			cout<<a<<" "<<workf()%q<<endl;
		}
		t--;
	}
	return 0;
}
