#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int d=0,w=1;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9'){d=(d<<3)+(d<<1)+c-'0';c=getchar();}
	return d*w;
}
const int N=1005,mod=998244353;
int n,m,cc,ff,cnt;
long long ansc,ansf;
bool s[N][N];
int ri[N][N],down[N][N];
char ch;
void deal(){
	ansc=0;
	for(int j=1;j<=m;j++){
		cnt=0;
		for(int i=2;i<=n;i++){
			if(!s[i][j]){
				cnt=0;
				continue;
			}
			if(ri[i][j]>1&&cnt>0){
				ansc=(ansc+1ll*cnt*(ri[i][j]-1))%mod;
				if(down[i][j]>1)
					ansf=(ansf+1ll*cnt*(ri[i][j]-1)%mod*(down[i][j]-1))%mod;
			}
			if(ri[i-1][j]>1){
				cnt+=ri[i-1][j]-1;
			}
		}
	}
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(false);
	cout.tie(0);
	int t=read(),id=read();
	while(t--){
		n=read(),m=read(),cc=read(),ff=read();
		ch=getchar();
		for(int i=1;i<=n;i++){
			while(ch!='0'&&ch!='1')
				ch=getchar();
			for(int j=1;j<=m;j++){
				if(ch=='0')
					s[i][j]=true;
				ch=getchar();
			}
		}
		for(int i=1;i<=n;i++){
			cnt=0;
			for(int j=m;j;j--){
				if(!s[i][j])
					cnt=0;
				else
					cnt++;
				ri[i][j]=cnt;
			}
		}
		for(int j=1;j<=m;j++){
			cnt=0;
			for(int i=n;i;i--){
				if(!s[i][j])
					cnt=0;
				else
					cnt++;
				down[i][j]=cnt;
			}
		}
		deal();
		cout<<cc*ansc%mod<<" "<<ff*ansf%mod;
	}
	return 0;
}
