#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int mod = 998244353;
int t,id,n,m,c,f;
int garden[maxn][maxn];
bool flaga,flagb;
int slove1() {
	if(n == 3 && m == 2) {
		int x = 0;
		for (int i = 1; i <=n; i++) {
			for (int j = 1; j <= m; j++) {
				if(i == 2 && j == 2) continue;
				if(garden[i][j] == 1) return x;
			}
		}
		return 1;
	}
	if(n == 4 && m == 2) {
		int x= 8;
		for (int i = 1; i <= n; i++) {
			if(garden[i][0] == 1 || garden[i][1] == 1) {
				
			}
		}
	}
	if(n > 4 && m == 2) {
		int x = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 2; j <= n; j++) {
				x+=n-j;
			}
		}
		return x;
	}
	if(flaga) {
		int len = n / 3;
		if(n % 3 == 2) len++;
		int x = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 2; j <= n; j++) {
				x+=n-j;
			}
		}
		return x * len;
	}
	}
int slove2() {
	return 142;
}
int main()  {
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	scanf("%d%d", &t, &id);
	while(t--) {
		flaga = true;
		flagb = true;
		scanf("%d%d%d%d", &n, &m, &c, &f);
		for (int i = 1; i <= n; i++) {
			string s;
			cin >> s;
			for (int j = 1; j <= m; j++) {
				garden[i][j] = s[j - 1] - '0';
			}
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j * 3 <= m; j++) {
				if(garden[i][j] != 1) flaga = false;
			}
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j * 4 <= m; j++) {
				if(garden[i][j] != 1) flagb = false;
			}
		}
		if(!c && !f) {
			printf("0 0\n");
		} else if(c && f) {
			cout << slove1()<< " ";
			if(n == 3) cout << 0 << endl;
			if(n == 4) cout << 1 << endl;
		} else if(c && !f) {
			cout << slove2() << 0 << endl;
		}
	}
	return 0;
}
