#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353;
const int N=1009;
typedef long long ll;
int T,id;
int n,m,c1,f1;
int a[N][N],size[N],sum[N][N];
struct node{
	int l,r;
}sum1[N][N],sum2[N];
ll ans1,ans2;
char c[N][N];
void solve(){
	for (int i=1;i<=n;i++)
		size[i]=1;
	for (int i=1;i<=m-1;i++){
		bool flag=1;
		ll ans=0;
		for (int j=1;j<=n-2;j++){
			while(i>=sum1[j][size[j]].r) size[j]++;
			if (sum1[j][size[j]].l>i) continue;
			for (int k=j+2;k<=n;k++){
				int tot2=1;
				if (sum[k][i]-sum[j-1][i]>0){
					break;
				}
				while(i>=sum1[k][size[k]].r) size[k]++;
				if (sum1[k][size[k]].l>i) continue;
				//cout<<"i,j,k:";
				//cout<<i<<' '<<j<<' '<<k<<endl;
				//cout<<"tot"<<size[k]<<' '<<size[j]<<endl;
				//cout<<sum1[j][size[j]].r<<' '<<sum1[k][size[k]].r<<endl;
				ans=(sum1[k][size[k]].r-i)*(sum1[j][size[j]].r-i)%MOD;
				ans1=(ans1+ans)%MOD;
				int e=k;
				while(e<n&&c[e+1][i]!='1'){
					e++;
				}
				//cout<<i<<' '<<j<<' '<<k<<' '<<e<<endl;
				ans2=(ans2+ans*(e-k))%MOD;
				//cout<<"ans1,ans2"<<' '<<ans1<<' '<<ans2<<endl;
			}
		}
	}
}

int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&T,&id);
	while(T--){
		ans1=ans2=0;
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++)
				sum[i][j]=sum1[i][j].l=sum1[i][j].r=0;
		//memset(size1,0,sizeof(size1));
		scanf("%d%d%d%d",&n,&m,&c1,&f1);
		
		for (int i=1;i<=n;i++){
			int last1=0,last2=1,tot=0;
			scanf("%s",c[i]+1);
			//cout<<endl;
			//cout<<c[i][3]<<endl;
			for (int j=1;j<=m;j++){
				
				if (c[i][j]=='1'&&((j-1)>=(last1+1))) {
					tot++;
					sum1[i][tot].l=last1+1,sum1[i][tot].r=j-1;
					//cout<<i<<' '<<tot<<' '<<sum1[i][tot].l<<' '<<sum1[i][tot].r<<endl;
					last1=j;
				}
			}
			if (last1<m){
				tot++;
				sum1[i][tot].l=last1+1,sum1[i][tot].r=m;
					//cout<<i<<' '<<tot<<' '<<sum1[i][tot].l<<' '<<sum1[i][tot].r<<endl;
	
			}
		}
		//cout<<"we";
		for (int i=1;i<=m;i++)
			for (int j=1;j<=n;j++){
				sum[j][i]=(c[j][i]-'0')+sum[j-1][i];
				//cout<<j<<' '<<i<<' '<<sum[j][i]<<endl;
			}
		 solve();
		 ans1=(ans1*c1)%MOD;
		//cout<<ans2<<endl;
		ans2=(ans2*f1)%MOD;
		printf("%lld %lld",ans1,ans2);
	}
	return 0;
}