#include<bits/stdc++.h>

using namespace std;
const int ms=998244353;
int T,id;
int n,m,c,f;
int ma[1010][1010];
int yycl[1010][1010];
int xycl[1010][1010];//prework
void fd() {
	if(c==0&&f==0) {
		cout<<0<<" "<<0<<endl;
	}
	unsigned long long ans=0,ans1=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(xycl[i][j]&&yycl[i][j]>=2){
				for(int k=i+2;k<=i+yycl[i][j];k++){
					if(!xycl[k][j]) continue;
					if(k<=i+yycl[i][j]-1){
						ans1+=xycl[i][j]*xycl[k][j]*(yycl[k][j]);
						ans1%=ms;	
					}
					ans+=xycl[i][j]*xycl[k][j];
					ans%=ms;
				}
			}
		}
	}
	cout<<(ans*c)%ms<<" "<<(ans1*f)%ms<<endl;
}
void solve() {
	
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			xycl[i][j]=yycl[i][j]=0;
		}
	}
	int cnt=-1;
	for(int i=1; i<=n; i++) {
		cnt=-1;
		for(int j=m; j>=1; j--) {
			if(ma[i][j]) {
				cnt=-1;
				xycl[i][j]=0;
				continue;
			}
			cnt++;
			xycl[i][j]=cnt;
		}
	}//heng xiang yu chu li
	cnt=-1;
	for(int j=1; j<=m; j++) {
		cnt=-1;
		for(int i=n; i>=1; i--) {
			if(ma[i][j]) {
				cnt=-1;
				yycl[i][j]=0;
				continue;
			}
			cnt++;
			yycl[i][j]=cnt;
		}
	}//zong xiang yu chu li
	fd();
}
int main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	while(T--) {
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for(int i=1; i<=n; i++) {
			for(int j=1; j<=m; j++) {
				char o;
				cin>>o;
				ma[i][j]=o-'0';
			}
		}
		solve();
	}
	return 0;
}
/*
1 0
4 3 1 1
001
010
000
000
*/
