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

template<class T>inline void read(T&x){
	char c,last=' ';
	while(!isdigit(c=getchar()))last=c;
	x=c^48;
	while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+(c^48);
	if(last=='-')x=-x;
}

const int MAXN=1e3+7,P=998244353;
int n,m,c,f;
string a[MAXN];
int row[MAXN][MAXN];
int col[MAXN][MAXN];

int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;read(T),read(id);
	while(T--){
		read(n),read(m),read(c),read(f);
		for(int i=1;i<=n;++i){
			cin>>a[i];a[i]=" "+a[i];
		}
		for(int i=1;i<=n;++i){
			for(int j=m;j>=1;--j){
				if(a[i][j]=='0')row[i][j]=row[i][j+1]+1;
			}
		}
		for(int j=1;j<=m;++j){
			for(int i=n;i>=1;--i){
				if(a[i][j]=='0')col[i][j]=col[i+1][j]+1;
			}
		}
		int C=0,F=0;
		for(int j=1;j<=m;++j){
			int sum=0;
			for(int i=1;i<=n;++i){
				if(a[i][j]=='1'){
					sum=0;
					continue;
				}
				C=(C+1ll*(row[i][j]-1)*sum%P)%P;
				F=(F+1ll*(row[i][j]-1)*sum%P*(col[i][j]-1)%P)%P;
				if(a[i-1][j]=='0')sum=(sum+row[i-1][j]-1)%P;
			}
		}
		cout<<1ll*c*C%P<<' '<<1ll*f*F%P<<'\n';
	}
	return 0;
}
