#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1005;
int n,m,a[maxn][maxn],f[maxn][maxn],ff[maxn][maxn];
char st[maxn];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	scanf("%d%d",&T,&id);
	while(T--){
		int C,F;
		ll ansc=0,ansf=0;
		scanf("%d%d%d%d",&n,&m,&C,&F);
		memset(f,0,sizeof(f));
		for(int i=1;i<=n;i++){
			scanf("%s",st);
			for(int j=1;j<=m;j++){
				a[i][j]=st[j-1]-48;
			}
			int k=m+1;
			for(int j=m;j;j--) a[i][j]?k=j:f[i][j]=k;
		}
		for(int j=1;j<=m;j++){
			int k=n+1;
			for(int i=n;i;i--) a[i][j]?k=i:ff[i][j]=k;
		}
		for(int j=1;j<=m;j++){
			ll s=0,s2=0;
			for(int i=1;i<=n;i++){
				if(a[i][j]){
					s=0;s2=0;continue;
				}
				int t=f[i][j]-j-1;
				ansc+=t*s;ansf+=t*s*(ff[i][j]-i-1);s+=s2;s2=t;
			}
		}
		printf("%lld %lld\n",ansc*C,ansf*F);
	}
	return 0;
}
