#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define each(x,v) for(auto&x:v)
using namespace std;
using LL=long long;
template<class T>void rd(T&x){
	int f=0,c;
	while(!isdigit(c=getchar()))f^=!(c^45);
	x=(c&15);
	while(isdigit(c=getchar()))x=x*10+(c&15);
	if(f)x=-x;
}
const int P=998244353;
int ad(int k1,int k2){return k1+k2<P?k1+k2:k1+k2-P;}
int su(int k1,int k2){return k1-k2<0?k1-k2+P:k1-k2;}
void uad(int&k1,int k2){(k1+=k2)>=P&&(k1-=P);}
void usu(int&k1,int k2){(k1-=k2)<0&&(k1+=P);}
int mu(int k1,int k2){return 1LL*k1*k2%P;}
const int N=1005;
int T,id,n,m,c,f,f1[N][N],f2[N][N],f3[N][N];
char s[N][N];
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	rd(T),rd(id);
	while(T--){
		rd(n),rd(m),rd(c),rd(f);
		rep(i,1,n)scanf("%s",s[i]+1);
		rep(i,0,n+1)rep(j,0,m+1){
			f1[i][j]=f2[i][j]=f3[i][j]=0;
		}
		int ansc=0,ansf=0;
		rep(i,1,n){
			per(j,m,1){
				if(s[i][j]!='0'){
					f2[i][j]=0;
				}else{
					f1[i][j]=f1[i][j+1]+1;
					if(i>=3&&s[i-1][j]=='0'){
						f3[i][j]=mu(f2[i-2][j],f1[i][j]-1);
						uad(ansc,mu(f2[i-2][j],f1[i][j]-1));
					}
					f2[i][j]=ad(f1[i][j]-1,f2[i-1][j]);
					uad(f3[i][j],f3[i-1][j]);
					uad(ansf,f3[i-1][j]);
				}
			}
		}
		if(!c)ansc=0;
		if(!f)ansf=0;
		printf("%d %d\n",ansc,ansf);
	}
	return 0;
}
