#include<bits/stdc++.h>
#define int long long
using namespace std;

typedef long long ll;

const int mod=998244353;
const int N=1e3+10;

int read() {

	int x=0,f=1;
	char ch=getchar();
	while(ch<48||ch>57) {
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>=48&&ch<=57) {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;

}

int n,m,c,f,p[N][N],q[N][N],p1[N];
char a[N][N];
int anc=0,anf=0;

void dfsc(int x,int y) {
	
	for(int i=0;i<n;i++) {
		
		p1[i]=p[i][y];
		
	}
	
	for(int i=x; i<n; i++) {

		if(p1[i]) {

			if(a[i+1][y]!='0') continue;
			for(int j=i+2; j<n; j++) {

				if(p1[j]) anc+=p1[i]*p1[j],anc%=mod;
				if(p1[j]&&a[j+1][y]=='0') anf+=p1[i]*p1[j]*q[j+1][y],anf%=mod;
				else {

					if(a[j][y]=='0') continue;
					else break;

				}

			}

		}

	}

}

int T,id;

signed main() {

	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read();
	id=read();
	while(T--) {

		n=read();
		m=read();
		c=read();
		f=read();
		for(int i=0; i<n; i++) {

			cin>>a[i];

		}
		memset(q,0,sizeof(q));
		for(int i=n-1; i>=0; i--) {

			for(int j=0; j<m; j++) {

				q[i][j]=0;
				if(a[i][j]=='0') q[i][j]++;
				if(a[i][j]=='0') q[i][j]+=q[i+1][j];

			}

		}


		int t=0;
		memset(p,0,sizeof(p));
		int o=0;
		for(int i=0;i<n;i++) {

			o=0;
			for(int j=m-1;j>=0;j--) {
				
				p[i][j]=0;
				if(a[i][j]=='0'&&a[i][j+1]=='0'&&j+1<m) p[i][j]=p[i][j+1]+1;
				
			}

		}
		for(int i=0; i<m; i++)
			dfsc(0,i);

		anc*=c;
		anf*=f;
		printf("%lld %lld\n",anc%mod,anf%mod);
		anc=0,anf=0;

	}

	return 0;
}