#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <unordered_map>

typedef long long LL;

using namespace std;

const int N = 1010, mod = 998244353;

int n, m;
int T, id;
int a[N][N];
char g[N][N];

void init(){
	
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= n; j ++){
			a[i][j] = 0;
		}
	}
}

LL solve_c(){
	
	LL cnt = 0;
	for(int i = 1; i <= n-2; i ++){
		for(int j = 1; j <= m-1; j ++){
			int i1 = i, j2 = j, cnty = 0;
			while(j2 <= m && g[i][j2] != '1'){
				if(j2 - j >= 1) cnty ++;
				j2 ++;
				
			}
//			printf("%d\n", j2);
			if(cnty >= 1){
				
				while(i1 <= n && g[i1][j] != '1'){
					
					if(i1 - i >= 2){
						int cntx = 0;
						int j1 = j;
						while(j1 <= m && g[i1][j1] != '1'){
							if(j1 - j >= 1) cntx ++;
							j1 ++;
						}
//						printf("%d %d %d %d\n",i1, j1, cntx, cnty);
						cnt = (cnt + (LL)cntx*cnty%mod) % mod;
//						printf("%d\n", cnt);
					}
					i1 ++;
				}
			}	
			
		}
	}
	
	return cnt;
	
}

LL solve_f(){
	LL cnt = 0;
	for(int i = 1; i <= n-1; i ++){
		for(int j = 1; j <= m-1; j ++){
			int i1 = i, j2 = j, cnty = 0;
			while(j2 <= m && g[i][j2] != '1'){
				if(j2 - j >= 1) cnty ++;
				j2 ++;
			}
			if(cnty >= 1){
				
				while(i1 <= n && g[i1][j] != '1'){
					
					
					if(i1 - i >= 2){
						int cntx = 0;
						int j1 = j;
						while(j1 <= m && g[i1][j1] != '1'){
							
							if(j1 - j >= 1) cntx ++;
							j1 ++;
						}
						if(cntx && cnty){
							int cntz = 0;
							int i2 = i1;
							while(i2 <= n && g[i2][j] != '1'){
								if(i2 - i1 >= 1) cntz ++;
								i2 ++;
							}
							cnt = (cnt + (LL)cntx*cnty%mod*cntz%mod) % mod;
						}
					}
					i1 ++;
				}
			}	
			
		}
	}
	
	return cnt;
}

int main(){
	
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	
	scanf("%d%d", &T, &id);
	
	while(T --){
		int C, F;
		LL c = 0, f = 0;
		scanf("%d%d%d%d", &n, &m, &C, &F);
		
		for(int i = 1; i <= n; i ++) scanf("%s", g[i] + 1);
			
//		for(int i = 1; i <= n; i ++){
//			for(int j = 1; j <= m; j ++){
//				cout<<g[i][j]<<" ";
//			}
//			cout<<"\n";
//		}
		
		if(C == 0 && F == 0){
			printf("0 0\n");
		}
		else{
			
				if(C == 0){
					f = solve_f();
					
					printf("0 %lld\n", f%mod);
				}
				else if(F == 0){
					c = solve_c();
					
					printf("%lld 0\n", c%mod);
				}
				else{
					c = solve_c();
					f = solve_f();
					
					printf("%lld %lld\n", c%mod, f%mod);
				}
			}
			
		}
		
	
	
	return 0;
}

/*
1 0
4 3 1 1
001
010
000
000


*/