#include<bits/stdc++.h>
using namespace std;
#define N 1005
#define mod 998244353
int n,m,c,f,x;
int mp[N][N];
int T,id;
long long ansc,ansf;
void file()
{
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
}
int get_tot(int i,int j) {
	int tot=0;
	while(mp[i][j]==0&&j<=m) tot++,j++;
	return tot;
}
int gett(int i,int j) {
	while(mp[i][j]==0&&i<=n) i++;
	return i-1;
}
int main() {
	file();
	cin>>T>>id;
	while(T--) {
		ansc=0;
		ansf=0;
		cin>>n>>m>>c>>f;
		for(int i=1; i<=n; i++) {
			string s;
			cin>>s;
			for(int j=1; j<=m; j++) {
				mp[i][j]=(s[j-1]=='1');
//			cout<<mp[i][j]<<" ";
			}
		}
//	cout<<get_tot(1,1)<<endl;
		if(c==0&&f==0) {
			cout<<0<<" "<<0;
			continue;
		}
		if(c==1) {
			for(int i=1; i<=n-2; i++) {
				for(int j=1; j<=m-1; j++) {
					if(mp[i][j]==1) continue;
					else if(get_tot(i,j)==1) continue;
					else if(mp[i+1][j]==1) continue;
					else {
						int k=get_tot(i,j)-1;
						//cout<<"i="<<i<<" "<<"j="<<j<<"k="<<k<<endl;
						for(int y=i+2; y<=n; y++) {
							//	cout<<get_tot(y,j)<<endl;
							if(mp[y][j]==1)break;
							else if(get_tot(y,j)>1) {
								//	cout<<"y="<<y<<" "<<get_tot(y,j)<<endl;
								ansc+=k*(get_tot(y,j)-1);
								ansc%=mod;
							}
						}
					}
				}
			}
		}
		if(f==1) {
			for(int i=1; i<=n-3; i++) {
				for(int j=1; j<=m-1; j++) {
					if(mp[i][j]==1) continue;
					else if(get_tot(i,j)==1) continue;
					else if(mp[i+1][j]==1) continue;
					else {
						int k=get_tot(i,j)-1;
						for(int y=i+2; y<=n-1; y++) {
							if(mp[y][j]==1)break;
							else if(get_tot(y,j)>1&&!mp[y+1][j]) {
								//	cout<<"y="<<y<<" "<<get_tot(y,j)<<" "<<gett(y,j)-y<<endl;
								ansf+=k*(get_tot(y,j)-1)*(gett(y,j)-y);
								ansf%=mod;
							}
						}
					}
				}
			}
		}
		cout<<ansc<<" "<<ansf<<endl;
	}
	return 0;
}
//6 6 1 1
//000010
//011000
//000110
//010000
//011000
//000000