#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
const int MOD=998244353;
int n,m,c,f;
int id;
char a[N][N];

inline void init(){
	scanf("%d%d%d%d",&n,&m,&c,&f);
	for(register int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
	}
	
	return;
}

int r[N][N];
int d[N][N];

void prepre(){
	memset(r,0,sizeof(r));
	memset(d,0,sizeof(d));
}

inline void pre(){
	prepre();
	//how right can it to
	for(register int i=1;i<=n;i++){
		for(register int j=m;j>=1;j--){
			if(a[i][j]=='1')
				r[i][j]=-1;
			else{
				r[i][j]=max(r[i][j+1],j);
			}
		}
	}
	//how down can it to
	for(register int j=1;j<=m;j++){
		for(register int i=n;i>=1;i--){
			if(a[i][j]=='1'){
				d[i][j]=-1;
			}
			else{
				d[i][j]=max(d[i+1][j],i);
			}
		}
	}
	
	return;
}

int cnt=0;

struct row{
	int i,r;//hang,you zhi
};

struct node{
	int file;//lie
	int u,d;//up down
	vector<row> right;//to the right
}C[N*N];

int Vc=0,Vf=0;

inline void solve(){
	Vc=0;
	Vf=0;
	cnt=0;
	for(register int j=1;j<=m;j++){
//		cout<<"j = "<<j<<endl;
		int now=1;
		while(now<=n){
//			cout<<"now = "<<now<<endl;
			if(a[now][j]=='0' && d[now][j]>now+1){
				cnt++;
				C[cnt].right.clear();
				C[cnt].u=now;
				C[cnt].d=d[now][j];
				C[cnt].file=j;
				for(register int i=now;i<=d[now][j];i++){
					if(r[i][j]>j){
						C[cnt].right.push_back({i,r[i][j]-j});
					}
				}
				now=d[now][j];
//				cout<<"down! now = "<<now<<endl;
			}
			now++;
		}
	}
	
	
	for(register int i=1;i<=cnt;i++){
		//for each C(F)
		
//		cout<<"C "<<i<<" : "<<endl;
//		cout<<"right size = "<<C[i].right.size()<<endl;
//		cout<<"u = "<<C[i].u<<endl;
//		cout<<"d = "<<C[i].d<<endl;
//		cout<<endl;
		for(register int j=0;j+1<=C[i].right.size();j++){
			int temp1=C[i].right[j].r;
			int temp_row1=C[i].right[j].i;
//			cout<<"j = "<<j<<endl;
//			cout<<"j.i = "<<C[i].right[j].i<<endl;
			for(register int k=j+1;k<=C[i].right.size()-1;k++){
				int temp2=C[i].right[k].r;
				int temp_row2=C[i].right[k].i;
				
				if(temp_row2-temp_row1<=1)
					continue;
//				cout<<"k = "<<k<<endl;
//				cout<<"k.i = "<<C[i].right[k].i<<endl;
//				cout<<"temp1 = "<<temp1<<endl;
//				cout<<"temp2 = "<<temp2<<endl;
				Vc+=temp1*temp2;
				Vc%=MOD;
				Vf+=temp1*temp2*(C[i].d-temp_row2);
				Vf%=MOD;
			}
		}
//		cout<<endl;
	}
	Vc*=c;
	Vc%=MOD;
	Vf*=f;
	Vf%=MOD;
	printf("%d %d\n",Vc,Vf);
	return;
}

int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T;
	scanf("%d%d",&T,&id);
	while(T--){
		init();
		pre();
		solve();
	}
	return 0;
}
//Please give me a full score!
//Please!

