#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll P = 998244353;
const int N = 1010;
int t,id;
int n,m,c,f;
ll ansc,anst;
char M[N][N];
int mp[N][N];
ll sum[N][N];
struct node{
	int line;
	int h,t;
};
vector<node> vc,vf;
void getc(){
	int l;
	for(int o=0;o<vc.size();o++){
		l=vc[o].line;
		for(int i=vc[o].h;i+1<vc[o].t;i++){
			for(int j=i+2;j<=vc[o].t;j++){
				ansc+=(((sum[i][l]-1)*(sum[j][l]-1))%P);
				ansc%=P;
			}
		}
	}
}
void getf(){
	int l;
	for(int o=0;o<vf.size();o++){
		l=vf[o].line;
		for(int i=vf[o].h;i+2<vf[o].t;i++){
			for(int j=i+2;j<vf[o].t;j++){
				anst+=(((sum[i][l]-1)*(sum[j][l]-1)*(vf[o].t-j))%P);
				anst%=P;
			}
		}
	}
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&t,&id);
	for(int T=0;T<t;T++){
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for(int i=1;i<=n;i++)
			scanf("%s",M[i]+1);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				mp[i][j]=int(M[i][j]-'0');
		for(int i=0;i<=n+1;i++)
			for(int j=0;j<=m+1;j++)
				sum[i][j]=0;
		for(int i=1;i<=n;i++){
			for(int j=m;j>=1;j--){
				if(mp[i][j]) sum[i][j]=0;
				else sum[i][j]=sum[i][j+1]+1;
			}
		}
		vc.clear();
		vf.clear();
		int head,tail;
		node wow;
		bool flag;
		for(int j=1;j<m;j++){
			head=0,tail=0,flag=0;
			for(int i=1;i<=n;i++){
				if(mp[i][j]==0){
					if(!flag){
						head=i;
						flag=1;
					}
					tail=i;
				}else{
					if(head+1<tail){
						wow.line=j,wow.h=head,wow.t=tail;
						vc.push_back(wow);
					}
					if(head+2<tail){
						vf.push_back(wow);
					}
					flag=0,head=0,tail=0;
				}
			}
			if(head+1<tail){
				wow.line=j,wow.h=head,wow.t=tail;
				vc.push_back(wow);
			}
			if(head+2<tail){
				vf.push_back(wow);
			}
		}
		ansc=0,anst=0;
		if(c) getc();
		if(f) getf();
		printf("%lld %lld\n",ansc,anst);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
