#include <bits/stdc++.h>
#define R register
using namespace std;
int n,m,mod=998244353;
int a[1005][1005];
int s[1005][1005];
int row_c[1005][1005];
int lin_c[1005][1005];
char cs;
inline int read(){
    register int s=0,w=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){
		if (ch=='-'){
			w*=(-1);
		}
		ch=getchar();
	}	
	while ('0'<=ch&&ch<='9'){
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*w;
}

inline void write (long long x){
	register int cnt=0;
	char f[205];
	while(x){
		f[++cnt]=x%10+'0';
		x=x/10;
	}
	while (cnt){
		putchar(f[cnt--]);
	}
}

void cl(){
	for (R int i=1;i<=n;i++){
		for (R int j=1;j<=m;j++){
			a[i][j]=s[i][j]=row_c[i][j]=lin_c[i][j]=0;
		}
	}
}

int main () {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t,op,c,f,cnt;
	long long gets,num1,num2,sc,sf,ur;
	t=read(),op=read();
	while (t) {
		/*memset(a,0,sizeof(a));
		memset(s,0,sizeof(s));
		memset(row_c,0,sizeof(row_c));
		memset(lin_c,0,sizeof(lin_c));*/
		sc=0,sf=0;
		n=read(),m=read(),c=read(),f=read();
		for (R int i=1; i<=n; i++) {
			for (R int j=1; j<=m; j++) {
				cin>>cs;
				a[i][j]=cs-'0';
				//cout<<i<<" "<<j<<" "<<a[i][j]<<endl;
				s[i][j]=a[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			}
		}
		for (R int i=1; i<=n; i++) {
			cnt=0;
			for (R int j=m; j>=1; j--) {
				row_c[i][j]=cnt;
				if (a[i][j]==0) {
					cnt++;
				} else {
					cnt=0;
				}
			}
		}
		for (R int j=1; j<=m; j++) {
			cnt=0;
			for (R int i=n; i>=1; i--) {
				lin_c[i][j]=cnt;
				if (a[i][j]==0) {
					cnt++;
				} else {
					cnt=0;
				}
			}
		}
		for (R int i1=1; i1+2<=n; i1++) {
			for (R int i2=i1+2; i2<=n; i2++) {
				for (R int j1=1; j1<=m; j1++) {
					gets=s[i2][j1]-s[i2][j1-1]-s[i1-1][j1]+s[i1-1][j1-1];
					if (gets==0) {
						num1=row_c[i1][j1],num2=row_c[i2][j1];
						if (i2!=n) {
							ur=lin_c[i2][j1]*num1*num2;
							ur=ur%mod;
							sf+=ur;
							sf=sf%mod;
						}
						sc+=num1*num2;
						sc=sc%mod;
					}
				}
			}
		}
		if (c==0){
			putchar('0');
		}else{
		    write(c*sc);	
		}
		putchar(' ');
		if (f==0){
			putchar('0');
		}else{
			write(f*sf);
		}
		putchar('\n');
		t--;
		cl();
	}
	return 0;
}
