#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const int mod=998244353;
char a[N][N];int u[N][N];
typedef long long ll;
void work(){
	int n,m,c,f;scanf("%d%d%d%d",&n,&m,&c,&f);
	for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) u[i][j]=0;
	for(int i=1;i<=n;i++){
		int last=m;//cout<<a[i]+1<<endl;
		for(int j=m;j>=1;j--){
			if(a[i][j]=='1') last=j-1;
			else u[i][j]=last;
			//cout<<last<<endl;
		}
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=m;j++) cout<<u[i][j]<<" ";
//		cout<<endl;
//	}
	ll ans=0;
	for(int j=1;j<m;j++){
		int last=0,last2=0;
		for(int i=n;i>=1;i--){
			if(a[i][j]=='1') {
				last=0;last2=0;
			}
			else {
				ans=(ans+(ll)(last-last2)*(u[i][j]-j)%mod)%mod;
				last=(last+u[i][j]-j)%mod;
				last2=u[i][j]-j;
			}
		}
		//cout<<ans<<endl;
	}
	printf("%lld ",ans*c%mod);
	ans=0;
	for(int j=1;j<m;j++){
		ll last=0,last2=0,last3=n;
		for(int i=n;i>=1;i--){
			if(a[i][j]=='1') {
				last=0;last2=0;last3=i-1;
			}
			else {
				ans=(ans+(ll)(last-last2)*(u[i][j]-j)%mod)%mod;
				last2=(u[i][j]-j)*(last3-i);
				last=(last+last2)%mod;
			}
		}
		//cout<<ans<<endl;
	}
	printf("%lld\n",ans*f%mod);
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;scanf("%d%d",&T,&id);
	while(T--) work();
}
