#include<bits/stdc++.h>
#define I inline
#define RI register int
#define rep(i,a,b) for(RI i=a;i<=b;++i)
#define dow(i,a,b) for(RI i=a;i>=b;--i)
using namespace std;
const int N=1005,mo=998244353;
int T,id,n,m,C,F,sum[N][N];
char c[N][N];
I int add(int a,int b){return a+b>=mo?a+b-mo:a+b; }
I int sub(int a,int b){ return a-b<0?a-b+mo:a-b; }
I int mul(int a,int b){ return 1ll*a*b%mo; }
I int fast(int a,int b=mo-2){
	RI res=1;while(b) b&1&&(res=mul(res,a)),a=mul(a,a),b>>=1;return res; }
I int solve1(int mi,int mj,int y){
	RI res=0,ans=0;
	rep(i,mi+1,mj) res=add(res,max(sum[i][y]-1,0));
	rep(i,mi,mj-2) res=sub(res,max(sum[i+1][y]-1,0)),
		ans=add(ans,mul(sum[i][y]-1,res));
	return ans;
}
I int solve2(int mi,int mj,int y){
	RI res=0,ans=0;
	rep(i,mi+1,mj) res=add(res,max(mul((sum[i][y]-1),(mj-i)),0));
	rep(i,mi,mj-3) res=sub(res,max(mul((sum[i+1][y]-1),(mj-i-1)),0)),
		ans=add(ans,mul(sum[i][y]-1,res));
	return ans;
}
I void solve(){
	scanf("%d%d%d%d",&n,&m,&C,&F);
	rep(i,1,n){
		scanf("%s",c[i]+1),sum[i][m+1]=0;
		dow(j,m,1) if(c[i][j]=='0') sum[i][j]=sum[i][j+1]+1;
		else sum[i][j]=0;
	}
	RI ans1=0,ans2=0;
	rep(y,1,m){
		for(RI mi=1,mj=1;mi<=n;mi=mj+1){
			mj=mi;
			if(c[mi][y]=='1') continue;
			while(mj<=n&&c[mj][y]=='0') ++mj;--mj;
			if(mj<=mi+1) continue;
			ans1=add(ans1,solve1(mi,mj,y));
			ans2=add(ans2,solve2(mi,mj,y));
		}
	}
	printf("%d %d\n",mul(ans1,C),mul(ans2,F));
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	while(T--) solve();
	return 0;
}