#include <bits/stdc++.h>
#define M 998244353
using namespace std;
int n,m,a[1019][1008],sumh[1009][1009],sumz[1009][1009],jin[1009][1009];
// sumh mean in x way 0's numbers , sumz mean in y way
// lh mean every hang's liantongkuai lz mean in ylie 
int q[1009][1009],qz[1009][1009];
int cnth,cntz; 
long long ansc,ansf;
int main(){// meiju zhongzhuandian
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t,id,c,f;
	scanf("%d%d",&t,&id);
	char ot;
	while(t--){
		scanf("%d%d%d%d",&n,&m,&c,&f);
		cnth=0,cntz=0;
		ansc=0,ansf=0;
		if(c==0&&f==0){
			printf("0 0\n");
			continue;
		}
		for(int i=1;i<=n+1;++i){
			for(int j=1;j<=m+1;++j){
				a[i][j]=0;
				sumh[i][j]=0;
				sumz[i][j]=0;
				q[i][j]=0;
				qz[i][j]=0;
			}
		}
		for(int i=1;i<=n;++i){
			for(int j=1;j<=m;++j){
				ot=getchar();
				while(!isdigit(ot))ot=getchar();
				a[i][j]=(int)(ot^48);
				if(a[i][j]==0)sumh[i][j]=sumh[i][j-1]+1;
				else {
					//for(int jj=lh[i][cnth]+2;jj<j;++jj)jin[i][jj]=j-1;
				//	lh[i][++cnth]=j-1;
					sumh[i][j]=0;
				}
			}
		}
		for(int i=1;i<=n;++i){
			for(int j=1;j<=m;++j){
				if(a[i][j+1]==1||j==m){
					if(a[i][j]==1)continue;
				//	cout<<"qwq";
					for(int jj=j-sumh[i][j]+1;jj<=j;++jj)jin[i][jj]=j;
				}
			}
		}
		for(int j=1;j<=m;++j){
			for(int i=1;i<=n;++i){
				if(a[i][j]==0){
					sumz[i][j]=sumz[i-1][j]+1;
				}
				else {
				//	lz[j][++cntz]=i-1;
					sumz[i][j]=0;
				}
			}
		}
		for(int j=1;j<=m;++j){
			for(int i=1;i<=n;++i){
				if(a[i+1][j]==1||i==n){
					if(a[i][j]==1)continue;
				//	cout<<"qwq";
					for(int ii=i-sumz[i][j]+1;ii<=i;++ii)qz[ii][j]=i;
				}
			}
		}
		for(int i=2;i<=n;++i){
			for(int j=1;j<m;++j){
				if(a[i][j]==1){
					q[i][j]=0;
				}
				else q[i][j]=q[i-1][j]+jin[i][j]-j+1;
			}
		}
		int uc=1;
		for(int i=1;i<n;++i){
			for(int j=1;j<m;++j){
				if(a[i][j]==1){
				//	uc++;
					continue;
				}
				long long c1=jin[i][j]-j,c2=0;
				if(c1==0)continue;
				if(a[i+1][j]==1)continue;
				for(int k=i+2;k<=n;++k){
					if(a[k][j]==1)break;
					c2+=jin[k][j]-j;
					if(k<n){
						ansf+=c1*(jin[k][j]-j)*1ll*(qz[k][j]-k);
					}
					ansf%=M;
				}
				ansc+=c1*c2;
				ansc%=M;
			}
		}
	/*	for(int i=1;i<=n;++i){
			for(int j=1;j<=m;++j){
				cout<<qz[i][j]<<" ";
			}
			cout<<"\n";
		}*/
		printf("%lld %lld\n",ansc*c,ansf*f%M);
	}
	
	return 0;
}