#include<bits/stdc++.h>
#define rr register
using namespace std;
inline int read(){
	int num=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') num=num*10+ch-'0',ch=getchar();
	return num; 
}
const int mod=998244353;
char tu[1010][1020];
int dp[1020],qian[1020],lf[1010];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	scanf("%d%d",&T,&id);
	//id=2;
	if(id==1){printf("%d %d\n",0,0);return 0;}
	while(T--){
		int ansc=0,ansf=0;
		memset(dp,0,sizeof(dp));
		memset(qian,0,sizeof(qian));
		int n,m,c,f;
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for(int i=1;i<=n;i++){
			scanf("%s",tu[i]+1);
			//cout<<tu[i]+1<<endl;
		}
		for(int k=1;k<=m;k++){
			memset(dp,0,sizeof(dp));
			memset(qian,0,sizeof(qian));
			memset(lf,0,sizeof(lf));
			int s=0;
			for(rr int i=1;i<=n;i++){
				if(tu[i][k]=='1'){
					//cout<<i<<' '<<dp[i]<<endl;
					s=i;
					memset(dp,0,sizeof(dp));
					memset(qian,0,sizeof(qian));
					memset(lf,0,sizeof(lf));
				}
				else{
					if(lf[i-1]) ansf=(ansf+lf[i-1])%mod;
					for(int j=k+1;j<=m;j++)
					{
						if(tu[i][j]=='0') dp[i]++;
						else break;
					}
					qian[i]=qian[i-1]+dp[i];
					ansc=(ansc+dp[i]*qian[i-2])%mod;
					lf[i]=(lf[i-1]+dp[i]*qian[i-2])%mod;
					//cout<<i<<' '<<qian[i]<<' '<<dp[i]<<endl;
					//cout<<i<<' '<<dp[i]<<endl;
				}
			}
		}
		cout<<ansc*c<<' '<<ansf*f<<endl;
	}
	return 0;
}
