#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int maxn=1100;
int a[maxn][maxn];
int t,id,n,m,c,f;
int main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>t>>id;
	while(t--) {
		long long ansc=0;
		long long ansf=0;
		char s[maxn];
		cin>>n>>m>>c>>f;
		if(c==0&&f==0) cout<<"0 0"<<endl;
		for(int i=1; i<=n; ++i) {
			cin>>s+1;
			for(int j=1; j<=m; ++j) {
				a[i][j]=s[j]-48;
			}
		}
		for(int i=1; i<=n; ++i) {
			for(int j=1; j<=m; ++j) {
				if(a[i][j]==1) a[i][j]=-1;
			}
		}
		for(int i=1; i<=n; ++i) {
			for(int j=m-1; j>=1; j--) {
				if(a[i][j]!=-1) a[i][j]=a[i][j+1]+1;
			}
		}
		for(int i=1; i<=m; ++i) {
			int cmt;
			for(int j=1; j<=n-2; ++j) {
				if(a[j][i]>0&&a[j+1][i]!=-1) {
					for(int k=j+2; k<=n; ++k) {
						cmt=0;
						if(a[k][i]==-1) break;
						for(int f=k+1; f<=n; ++f) {
							if(a[f][i]==-1) break;
							cmt+=1;
						}
						ansc=(ansc+a[j][i]*a[k][i])%mod;
						ansf=(ansf+a[j][i]*a[k][i]*cmt)%mod;
					}
				}
			}
		}
		ansc*=c;
		ansf*=f;
		cout<<ansc<<" "<<ansf<<endl;
//		for(int i=1;i<=n;++i){
//			for(int j=1;j<=m;++j) cout<<a[i][j];
//			cout<<endl;
//		}
	}
	return 0;
}
//fkU
