#include<iostream>
#define ll long long
using namespace std;
ll read(){
	ll w=0,f=1;
	char c=getchar();
	if(c<'0'||c>'9'){
		f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		w=w*10+c-'0';
		c=getchar();
	}
	return w*f;
}
void write(ll x){
	if(x<0){
		putchar('-');
		x*=-1;
	}
	if(x>=10){
		write(x/10);
	}
	putchar(x%10+'0');
}
const int N=1e3+5,mod=998244353;
int t,id;
ll num;
int n,m,c,f;
char a[N][N];
ll checkc(int x,int y){
	ll pos=0,ans2=0;
	for(int i=x+1;i<=n;i++){
		if(a[i][y]=='1'){
			break;
		}
		pos++;
	}
	//cout<<x<<" "<<y<<" "<<pos<<endl;
	if(pos<2){
		return 0;
	}
	else{
		ll ans=0;
		for(int j=y+1;j<=m;j++){
			if(a[x][j]=='1'){
				break;
			}
			ans++;
		}
		if(ans==0){
			return 0;
		}
		for(int i=x+2;i<=x+pos;i++){
			ll ans1=0;
			for(int j=y+1;j<=m;j++){
				if(a[i][j]=='1'){
				    break;
		        }
		        ans1++;
			}
			ans2+=ans*ans1;
			//cout<<ans*ans1<<endl;
		}
	}
	return ans2;
}
ll checkf(ll x,ll y){
	ll pos=0,ans2=0;
	for(int i=x+1;i<=n;i++){
		if(a[i][y]=='1'){
			break;
		}
		pos++;
	}
    //cout<<x<<" "<<y<<" "<<pos<<endl;
	if(pos<3){
		return 0;
	}
	else{
		ll ans=0;
		for(int j=y+1;j<=m;j++){
			if(a[x][j]=='1'){
				break;
			}
			ans++;
		}
		/*cout<<endl;
		cout<<ans<<endl;
		cout<<endl;*/
		if(ans==0){
			return 0;
		}
		for(int i=x+2;i<=x+pos-1;i++){
			ll ans1=0;
			for(int j=y+1;j<=m;j++){
				if(a[i][j]=='1'){
				    break;
		        }
		        ans1++;
			}
			ans2+=ans*ans1*(pos+x-i);
		}
	}
	//cout<<ans2<<endl;
	return ans2;
}
void dfs1(int x,int y){
	if(y==m+1){
		x++;
		y=1;
	}
	if(x==n+1){
		return ;
	}
	if(a[x][y]=='1'){
		dfs1(x,y+1);
	}
	else{
		num+=checkc(x,y);
		dfs1(x,y+1);
	}
}
void dfs2(int x,int y){
	if(y==m+1){
		x++;
		y=1;
	}
	if(x==n+1){
		return ;
	}
	if(a[x][y]=='1'){
		dfs2(x,y+1);
	}
	else{
		num+=checkf(x,y);
		dfs2(x,y+1);
	}
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	t=read(),id=read();
	for(int i=1;i<=t;i++){
		num=0;
		n=read(),m=read(),c=read(),f=read();
		if(c==0&&f==0){
			write(0);
			putchar(10);
			continue;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>a[i][j];
			}
		}
		/*for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cout<<a[i][j]<<" ";
			}
			cout<<endl;
		}*/
		dfs1(1,1);
		write((num*c)%mod);
		cout<<" ";
		num=0;
		dfs2(1,1);
		write((num*f)%mod);
		putchar(10);
	}
	return 0;
}
