#include<bits/stdc++.h>
#define MOD 998244353
using namespace std;
long long T,id,ri[1005][1005],dow[1005][1005],n,m,c,f,cans[1005][1005],ansc,fans[1005][1005],ansf;
bool ff[1005][1005];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>T>>id;
	while(T>0){
		memset(ff,true,sizeof(ff));
		memset(ri,0,sizeof(ri));
		memset(cans,0,sizeof(cans));
		memset(fans,0,sizeof(fans));
		memset(dow,0,sizeof(dow));
		ansc=0,ansf=0;
		cin>>n>>m>>c>>f;
		char ddddd;
		for(int i=1;i<=n;i++)
		    for(int j=1;j<=m;j++){
		    	cin>>ddddd;
		    	if(ddddd=='1')ff[i][j]=true;
		    	if(ddddd=='0')ff[i][j]=false;
			}
		/*for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
		    	cout<<ff[i][j];
			}cout<<endl;
		}*/
		for(int i=1;i<=n;i++)
		    for(int j=m;j>0;j--){
		    	if(!ff[i][j+1]&&!ff[i][j]){
		    		ri[i][j]=ri[i][j+1]+1;
				}
			}
		for(int i=n;i>0;i--){
			for(int j=1;j<=m;j++){
				if(!ff[i][j]&&!ff[i+1][j])dow[i][j]=dow[i+1][j]+1;
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				dow[i][j]=dow[i][j]*ri[i][j];
			}
		}
		for(int i=n;i>0;i--){
			for(int j=1;j<=m;j++){
				if(!ff[i+1][j]&&!ff[i+2][j]){
					cans[i][j]=cans[i+1][j]+ri[i+2][j];
					cans[i][j]%=MOD;
				}
				if(!ff[i+1][j]&&!ff[i+2][j]){
					fans[i][j]=fans[i+1][j]+dow[i+2][j];
					fans[i][j]%=MOD;
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				ansc+=cans[i][j]*ri[i][j];
				ansc%=MOD;
				ansf+=fans[i][j]*ri[i][j];
				ansf%=MOD;
			}
		}cout<<ansc*c<<' '<<ansf*f<<endl;
		T--;
	}
}
