//how to find ccf?????
#include<bits/stdc++.h>
using namespace std;
int m,n,s,cnt,t,id,c=1,f=1;
long long ansc,ansf;
long long mod=998244353;
int a[1011][1011];
int main() {
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&t,&id);
	while(t--) {
		scanf("%d%d%d%d",&n,&m,&c,&f);
		if(c==0&&f==0) {
			cout<<0<<' '<<0<<endl;
			continue;
		}
		for(int i=1; i<=n; i++) {
			for(int j=1; j<=m; j++) {
				char ccf;//why cant scanf("%c",&ccf)
				cin>>ccf;
				if(ccf=='1') {
					a[i][j]=1;
				} else a[i][j]=0;
			}
		}
		for(int i=1; i<=n; i++) {
			for(int j=1; j<=m; j++) {
				if(a[i][j]==1)continue;
				int tmp=1;
				for(tmp; tmp+j<=m; tmp++) {
					if(a[i][j+tmp]==1)break;
				}
				if(tmp<2)continue;
				int k=1;
				for(k=1; i+k<=n; k++) {
					if(a[i+k][j]==1) {
						break;
					}
					if(k>=2) {
						int l=1;
						int up0=0;
						int down0=0;
						bool f1=0;
						bool f2=0;
						for(l; j+l<=m; l++) {
							if(a[i][j+l]==0&&f1==0) {
								up0++;
							} else if(a[i][j+l]==1)f1=1;
							if(a[i+k][j+l]==0&&f2==0) {
								down0++;
							} else if(a[i+k][j+l]==1)f2=1;
						}
						if(up0==0||down0==0)continue;
						ansc=(ansc+up0*down0%mod)%mod;
						int kfc=k+1;
						int cfk=0;
						for(kfc; kfc+i<=n; kfc++) {
							if(a[i+kfc][j]==0) {
								cfk++;
							} else break;
						}
						ansf=(ansf+up0*down0%mod*cfk%mod)%mod;
					}
				}

			}
		}
		cout<<ansc*c<<' '<<ansf*f<<endl;
	}
	return 0;
}
