#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fll
#define For(i_,l_,r_) for(int i_=(l_);i_<=(r_);i_++)
#define Rep(i_,l_,r_) for(int i_=(l_);i_>=(r_);i_--)
using namespace std;
#define Ci const int
#define Cl const ll
#define Cul const ull
#define Cc const char
int _l=-1,_p;Ci inS=1<<18,ouS=1<<18;
char _c[inS],*_u=_c,*_v=_c,_b[ouS],_d[55];
#define getchar() (_u==_v&&(_v=(_u=_c)+fread(_c,1,inS,stdin),_u==_v)?EOF:*_u++)
#define _c_ getchar()
template<typename T=int>inline T read(){
	char ch=_c_;T X=0;bool fl=0;while(ch<48||ch>57)fl|=(ch==45),ch=_c_;
	while(ch>47&&ch<58)X=X*10+(ch^48),ch=_c_;return fl?-X:X;
}
inline char Gec(){
	char ch=_c_;while(ch<33)ch=_c_;return ch;
}
inline void flush(){fwrite(_b,1,_l+1,stdout);_l=-1;}
inline void _pc(Cc c){if(c!=-1)_b[++_l]=c;}
inline void _chf(){if(_l>(ouS>>1))flush();}
template<typename T=int>inline void write(T x,Cc c=-1){
	if(x<0)_pc(45),x=-x;do{_d[++_p]=(x%10)|48;}while(x/=10);
	do{_b[++_l]=_d[_p];}while(--_p);_pc(c);_chf();
}
inline void write(Cc c){_pc(c);}
inline void puc(Cc c){_pc(c);_chf();}
template<typename T,typename...A>void write(T x,A...a){write(x);write(a...);}
const int M=998244353;
inline int Add(Ci x,Ci mod=M){return x>=mod?x-mod:x;}
int T,id,n,m,QC,QF,a[1005][1005],r[1005][1005],d[1005][1005];
int f[1005][1005],f2[1005][1005];
inline void ypa(){
	n=read(),m=read(),QC=read(),QF=read();
	For(i,1,n)
		For(j,1,m)a[i][j]=Gec()^48;
	For(i,1,n){
		r[i][m+1]=m+1;
		Rep(j,m,1){
			if(a[i][j])r[i][j]=j;
			else r[i][j]=r[i][j+1];
//			cerr<<i<<' '<<j<<' '<<r[i][j]<<"\n";
		}
	}
	For(j,1,m){
		d[n+1][j]=n+1;
		Rep(i,n,1){
			if(a[i][j])d[i][j]=i;
			else d[i][j]=d[i+1][j];
		}
	}
	int ansc=0,ansf=0;
//	For(i,1,n)
//		For(j,1,m)
//			cerr<<i<<' '<<j<<' '<<r[i][j]<<' '<<d[i][j]<<'\n';
	For(i,2,n)
		For(j,1,m){
			if(!a[i][j]){
				int u=max(r[i-1][j]-j-1,0);
				f[i][j]=Add(f[i-1][j]+u);
//				cerr<<"!! "<<i<<' '<<j<<' '<<f[i][j]<<' '<<u<<'\n';
				ansc=(ansc+1ll*f[i-1][j]*max(0,r[i][j]-j-1))%M;
				ansf=(ansf+1ll*f[i-1][j]*max(0,r[i][j]-j-1)*max(0,d[i][j]-i-1))%M;
			}
		}
	write(ansc*QC,' ',ansf*QF,'\n');
	For(i,1,n+1)
		For(j,1,m+1)f[i][j]=r[i][j]=d[i][j]=a[i][j]=0;
}
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	T=read(),id=read();
	For(I,1,T)ypa();
	flush();return 0;
}
