#include<bits/stdc++.h>
using namespace std;
#define int long long
struct reader{
	#define gc ch=getchar()
	template<typename T>
	reader&operator>>(T&x){
		char gc;x=0;int f=1;
		for(;!isdigit(ch);gc)ch=='-'&&(f=-f);
		for(;isdigit(ch);gc)x=x*10+ch-'0';
		x*=f;return*this;
	}
}fin;
const int N=1003,p=998244353;
int T,m,n,id,c,f,r[N][N],C,F,rw[N][N],cn,cl[N][N],lcn,ccl[N][N];
char ch;
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
//	freopen("plant3.in","r",stdin);
	//freopen("plant.out","w",stdout);
	fin>>T>>id;
	while(T--){
		fin>>n>>m>>c>>f;C=F=0;
		for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)r[i][j]=rw[i][j]=cl[i][j]=ccl[i][j]=0;
		for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf(" %c",&ch),r[i][j]=ch=='1';
		for(int i=1;i<=n;i++){
			cn=0;
			for(int j=m;j;j--){
				if(r[i][j])cn=0;
				else cn++,rw[i][j]=max(cn-1,0ll);
			}
		}
		for(int j=1;j<=m;j++){
			cn=lcn=0;
			for(int i=1;i<=n;i++){
				if(r[i][j])cn=lcn=0;
				else{
					cl[i][j]=rw[i][j]*lcn%p;
					(C+=cl[i][j])%=p;
					lcn=cn,(cn+=rw[i][j])%=p;
				}
			}
		}
		for(int j=1;j<=m;j++){
			cn=0;
			for(int i=1;i<=n;i++){
				if(r[i][j])cn=0;
				else{
					ccl[i][j]=cn;
					(F+=ccl[i][j])%=p;
					(cn+=cl[i][j])%=p;
				}
			}
		}
//		for(int i=1;i<=n;puts(""),i++)for(int j=1;j<=m;j++)printf("%d ",rw[i][j]);puts("");
//		for(int i=1;i<=n;puts(""),i++)for(int j=1;j<=m;j++)printf("%d ",cl[i][j]);puts("");
//		for(int i=1;i<=n;puts(""),i++)for(int j=1;j<=m;j++)printf("%d ",ccl[i][j]);
		printf("%lld %lld\n",c*C%p,F*f%p);
	}
}