#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
const int MOD = 998244353;
int a[N][N];
int n,m;
long long ans1,ans2;
long long r[N][N];
long long d[N][N];
int c,f;
int T,id;
void you(){
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			int tem = j+1;
			if(a[i][j] == 1) continue;
			while(a[i][tem] != 1 && tem <= m){
				tem++;
				r[i][j]++;
			}
		}
	}
}
void xia(){
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			int tem = i+1;
			if(a[i][j] == 1) continue;
			while(a[tem][j] != 1 && tem <= n){
				tem++;
				d[i][j]++;
			}
		}
	}
}
int main()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
    cin >> T >> id;
    while(T--){
    memset(a,0,sizeof(a));
    memset(r,0,sizeof(r));
    memset(d,0,sizeof(d));
    ans1 = 0;
    ans2 = 0;
    cin >> n >> m;
    cin >> c >> f;
    char ch ;
    for(int i = 1;i <= n;i++){
    	for(int j = 1;j <= m;j++){
    		ch = getchar();
    		if(ch == '\n') ch = getchar();
    		a[i][j] = ch-'0';
		}
	}
    if(c == 0 && f == 0){
    	cout << "0" << " " << "0" << endl;
    	continue;
	}
    you();
    xia();
    for(int i = 1;i <= n;i++){
    	for(int j = 1;j <= m;j++){
    		if(d[i][j] >= 2){
    			for(int k = d[i][j];k >= 2;k--){
    				ans1 += r[i+k][j]*r[i][j];
    				ans1 %= MOD;
    				ans2 += r[i+k][j]*r[i][j]*(d[i][j]-k);
    				ans2 %= MOD;
				}
			}
		}
	}
	cout << ans1*c << " " <<  ans2*f << endl;
	}
	return 0;
}
