#include<bits/stdc++.h>
#define ll long long
#define PII pair<int, int>

using namespace std;

const int mod = 998244353;
const int N = 3e3 + 10;
int _, id;
int n, m, c, f;
int a[N][N];
string s;
ll rs1, rs2;

PII fx(int x, int y){
	int i = x, j = y, ans1 = 0, ans2 = 0;
	while(i <= n and a[i][y] == 0)
			i ++;
	while(j <= m and a[x][j] == 0)
			j ++;
	int base2 = j - y - 1;
	for(int k = x + 2; k < i; k ++){
		int i1 = k, j1 = y;
		while(j1 <= m and a[i1][j1] == 0)
				j1 ++;
		int base3 = j1 - y - 1;
		ans1 = ans1 % mod + base3 * base2 % mod;
		ans2 = ans2 % mod + base3 * base2 * (i - k - 1) % mod;
	}
	return make_pair(ans1 % mod, ans2 % mod);
}

int main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	scanf("%d%d", &_, &id);
	while(_ --){
		scanf("%d%d%d%d", &n, &m, &c, &f);
		
		memset(a, -1, sizeof a);	
		rs1 = rs2 = 0;
		
		for(int i = 1; i <= n; i ++){
			cin >> s;
			for(int j = 0; j < m; j ++)
				if(s[j] == '1') a[i][j + 1] = 1;
				else a[i][j + 1] = 0;
		}
		int ans = 0;
		for(int i = 1; i <= n; i ++)
			for(int j = 1; j <= m; j ++){
				if(a[i][j] == 1) continue;
				PII wxk = fx(i, j);
				rs1 = rs1 % mod + wxk.first % mod;
				rs2 = rs2 % mod + wxk.second % mod;
			}
		printf("%lld %lld \n", rs1 % mod, rs2 % mod);
	}
	
	
	return 0;
}
/*
1 0
4 3 1 1
001
010
000
000
*/