#include <cstdio>
#define ll long long

int read(){
	int x =0, f =0; char c =getchar();
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

const int MAXN =1020, M =998244353;

int n, m, c, f;
int ansC, ansF;
int a[MAXN][MAXN];
int rmax[MAXN];

int main(){
	freopen("plant.in", "r", stdin);
	freopen("plant.out", "w", stdout);
	
	for(int tt =0, T =read(), id =read(); tt < T; ++tt){
		ansC =0, ansF =0;
		for(int i =0; i < n; ++i)
			rmax[i] =0;
		
		n =read(), m =read(), c =read(), f =read();
		for(int i =0; i < n; ++i){
			char cc =getchar();
			while(cc != '0' && cc != '1') cc =getchar();
			for(int j =0; j < m; ++j)
				a[i][j] =cc-'0', cc =getchar();
		}
		for(int j =m-1; j >= 0; --j){
			for(int i =0; i < n; ++i){
				if(a[i][j])
					rmax[i] =0;
				else
					++rmax[i];
			}
			for(int i =n-1, sum =0, psum =-1; i >= 0; --i){
				if(rmax[i] == 0)
					sum =0, psum =-1;
				else{
					if(psum != -1)
						ansC =(ansC+1ll*(rmax[i]-1)*psum%M)%M;
					psum =sum, sum =sum+rmax[i]-1;
				}
			}
			for(int i =n-1, sum =0, cnt =0, psum =-1; i >= 0; --i){
				if(rmax[i] == 0)
					sum =0, cnt =0, psum =-1;
				else{
					if(psum != -1)
						ansF =(ansF+1ll*(rmax[i]-1)*psum%M)%M;
					psum =sum, sum =(sum+1ll*(rmax[i]-1)*cnt%M)%M;
					++cnt;
				}
			}
		}
		
		printf("%d %d\n", int(1ll*ansC*c%M), int(1ll*ansF*f%M));
	}
}
