#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const long long mod=998244353;
long long fin[N][N];
char a[N][N];
int read(){
	int f=1,l=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		l=l*10+(c-'0');
		c=getchar();
	}
	return f*l;
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t=read(),p=read();
	while(t--)
	{
		int n=read(),m=read(),c=read(),f=read();
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			cin>>a[i][j];
		for(int i=1;i<=n;i++)
			fin[i][m+1]=(long long)0;
		for(int i=1;i<=n;i++)
			a[i][m+1]='1';
		for(int i=1;i<=n;i++)
			for(int j=m;j;j--)
				if(a[i][j+1]=='1') fin[i][j]=(long long)0;
					else fin[i][j]=fin[i][j+1]+(long long)1;
		long long now=(long long)0;
		long long last=0;
		long long ans=0;
		long long ansf=0;
		long long nowf=0;
		for(int j=1;j<=m;j++)
		{
			now=(long long)0;
			last=(long long)0;
			nowf=(long long)0;
			for(int i=1;i<=n;i++)
			{
				if(a[i][j]=='1'){
					last=(long long)0;
					now=(long long)0;
					nowf=(long long)0;
					continue;
				}
				ansf+=nowf;
				nowf+=fin[i][j]*now;
				ansf%=mod;
				ans+=fin[i][j]*now;
				ans%=mod;
				now+=last;
				last=fin[i][j];
			}
		}	
		cout<<ans*(long long)c<<' '<<ansf*(long long)f<<'\n';
	}
	return 0;
}