#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N(1005);
const ll P(998244353);
int n,m,cb,fb;bool a[N][N];
ll C[N][N],F[N][N];
ll b[N][N],ad[N][N];
char ch[N];
void solve(){
	cin>>n>>m>>cb>>fb;
	for(int i=1;i<=n;++i){
		cin>>(ch+1);
		for(int j=1;j<=m;++j){
			a[i][j]=ch[j]-'0';a[i][j]^=1;
		}
		for(int j=m;j>=1;--j){
			if(!a[i][j]) b[i][j]=0;
			else if(a[i][j+1])b[i][j]=b[i][j+1]+1;
		}
	}
	for(int j=1;j<=m;++j){
		for(int i=1;i<=n;++i){
			if(!a[i][j]){
				ad[i][j]=0;
				continue;
			}
			ad[i][j]=ad[i-1][j]+b[i][j];
		}
	}
	ll ansc=0,ansf=0;
	for(int i=3;i<=n;++i){
		for(int j=1;j<=m;++j){
			if(!a[i-1][j]||!a[i-2][j]||!a[i][j]) continue;
			C[i][j]=ad[i-2][j]*b[i][j]%P;
			ansc=(ansc+C[i][j])%P;
		}
	}int cnt=0;
	for(int j=1;j<=m;++j){
		cnt=0;
		for(int i=n;i>=3;--i){
			if(!a[i][j]) cnt=0;
			else if(a[i+1][j])cnt++;
			ansf=(ansf+C[i][j]*cnt%P)%P;
		}
	}
	cout<<ansc*cb<<' '<<ansf*fb<<endl;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			C[i][j]=0;
			F[i][j]=0;
			a[i][j]=0;
			b[i][j]=0;
			ad[i][j]=0;
		}
	}
}
int main(){
//	freopen("plant.in","r",stdin);
//	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(0);
	int T,id;
	cin>>T>>id;
	while(T--) solve();	
}