#include<bits/stdc++.h>
using namespace std;
#define gc getchar
#define N 1005
#define ll long long
#define mod 998244353
char mp[N][N];
int n,m,t,id,c,f;
ll cl[N][N],cd[N][N],fc[N][N],ff[N][N],ansc,ansf;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>t>>id;
	while(t--){
		cin>>n>>m>>c>>f;
		if(f==0&&c==0){
			cout<<"0 0\n";
			continue;
		}
		ansc=ansf=0;
		for(int i=1;i<=n;i++) cin>>mp[i];
		for(int i=0;i<=n+1;i++) for(int j=m+1;j>=0;j--){
			cl[i][j]=cd[i][j]=fc[i][j]=ff[i][j]=0;	
		}
		for(int i=1;i<=n;i++) for(int j=m;j>0;j--){
			if(mp[i][j-1]=='0')
				cl[i][j]=cl[i][j+1]+1;
		}
		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
			if(mp[i][j-1]=='1') continue;
			cd[i][j]=max(0ll,cd[i-1][j]+cl[i][j]-1);
			if(i>2&&mp[i-1][j-1]=='0') fc[i][j]=cd[i-2][j]*(cl[i][j]-1)%mod;
			ansc=(ansc+fc[i][j])%mod;
			ff[i][j]=(ff[i-1][j]+fc[i-1][j])%mod;
			ansf=(ansf+ff[i][j])%mod;
		}
		cout<<c*ansc<<" "<<f*ansf<<endl;
	}
	return 0;
}

