#include <bits/stdc++.h>
#define F(i,f,t) for(int i=(f),_end=(t);i<=_end;i++)
#define D(i,f,t) for(int i=(f),_end=(t);i>=_end;i--)
#define int long long
using namespace std;

template<typename T>
void re(T&a) {
	char c;
	T f=1;a=0;
	while(c=getchar(),!isdigit(c)) if(c=='-') f=-1;
	while(isdigit(c)) a=a*10+c-'0',c=getchar();
	a*=f;
}
template<typename T,typename ...Arg>
void re(T&a,Arg&...arg) {
	re(a),re(arg...);
}
const int N=1e3+50,M=100000,md=998244353;
typedef int intn[N],intm[M];

int n,m,vc,vf;
char mp[N][N];
int ymx[N][N],C[N][N];
inline void wk() {
	re(n,m,vc,vf);
	F(i,1,n) scanf("%s",mp[i]+1);
	F(i,1,n) {
		ymx[i][m+1]=0;	
		D(j,m,1) ymx[i][j]=mp[i][j]=='1'?0:ymx[i][j+1]+1;
	}
	int An1=0,An2=0;
	F(j,1,m) {
		int sm=0,lst=0;
		F(i,1,n) {
			if(mp[i][j]=='1') lst=sm=0;
			else C[i][j]=(ymx[i][j]-1)*lst%md,(An1+=C[i][j])%=md,lst=sm,(sm+=ymx[i][j]-1)%=md;
		}
	} 
	F(j,1,m) {
		int sm=0;
		F(i,1,n) {
			if(mp[i][j]=='1') sm=0;
			else (An2+=sm)%=md,(sm+=C[i][j])%=md;
		}
	}
	An1=An1*vc%md,An2=An2*vf%md;
	printf("%lld %lld\n",An1,An2);
}

signed main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	re(T,id);
	while(T--) wk();
	return 0;
}
