#include<bits/stdc++.h>
using namespace std;
const int Mod=998244353;
int n,m,c,f;
int T,idd;
bool mp[1005][1005];
int srow[1005][1005];
int sspan[1005][1005];
long long ans1,ans2;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	//put my code here
	scanf("%d%d",&T,&idd);
	while(T--){
		scanf("%d%d%d%d\n",&n,&m,&c,&f);
		if(c==0&&f==0){
			printf("0 0\n");
			continue;
		}
		for(int i=1;i<=n;++i){
			char t;
			for(int j=1;j<=m;++j){
				t=getchar();
				mp[i][j]=(t=='1'? 1:0);
			}
			t=getchar();
			for(int j=m;j>=1;--j){
				if(!mp[i][j])srow[i][j]=srow[i][j+1]+1;
				else srow[i][j]=0;
			}
		}
		for(int j=1;j<=m;++j){
			for(int i=n;i>=1;--i){
				if(!mp[i][j])sspan[i][j]=sspan[i+1][j]+1;
				else sspan[i][j]=0;
			}
		}
		ans1=0,ans2=0;
		for(int j=1;j<=m;++j){
			for(int i1=1;i1<=n;++i1){
				if(srow[i1][j]<=1)continue;
				for(int i2=i1+2;i2<=n;++i2){
					if(i2-i1!=sspan[i1][j]-sspan[i2][j])break;
					if(srow[i2][j]<=1)continue;
					ans1=(ans1+1ll*(srow[i1][j]-1)*(srow[i2][j]-1))%Mod;
					if(sspan[i2][j]<=1)continue;
					ans2=(ans2+1ll*(srow[i1][j]-1)*(srow[i2][j]-1)*(sspan[i2][j]-1))%Mod;
				}
			}
		}
		printf("%lld %lld\n",c*ans1,f*ans2);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
