#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ri register
#define in inline
#define INF 0x3f3f3f3f
using namespace std;
const int N=1010;
const int mod=998244353;
char ch[N][N];
int mp[N][N];
int visx[N][N],visy[N][N];
int n,m,c,f,id;
signed main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int T,id;
	cin >> T >> id;
	while(T--){
		int ansc=0,ansf=0;
		cin >> n >> m >> c >> f;
		if(c==0&&f==0) cout << "0 0\n";
		else{
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					cin >> ch[i][j];
					mp[i][j]=ch[i][j]-'0';
				}
			}
			for(int i=1;i<=n;i++){
				int v=m+1;
				for(int j=m;j>=1;j--){
					if(mp[i][j]==0) visx[i][j]=v;
					else v=j;
				}
			}
			for(int i=1;i<=m;i++){
				int v=n+1;
				for(int j=n;j>=1;j--){	
					if(mp[j][i]==0) visy[j][i]=v;
					else v=j;
				}
			}
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					if(visx[i][j]>j+1&&visy[i][j]>i+1){
						for(int k=i+2;k<=visy[i][j]-1;k++){
							if(visx[k][j]>j+1){
								ansc=(ansc+(visx[i][j]-j-1)*(visx[k][j]-j-1)%mod)%mod;
							}
						}
					}
				}
			}
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					if(visx[i][j]>j+1&&visy[i][j]>i+2){
						for(int k=i+2;k<=visy[i][j]-2;k++){
							if(visx[k][j]>j+1&&visy[k][j]>k+1){
								ansf=(ansf+((visx[i][j]-j-1)*(visx[k][j]-j-1)%mod)*(visy[k][j]-k-1)%mod)%mod;
							}
						}
					}
				}
			}
			cout << ansc << " " << ansf << "\n";
//			cout << ansc;
//			for(int i=1;i<=n;i++){
//				for(int j=1;j<=m;j++){
//					ax[i][j]=ax[i][j-1]+mp[i][j];
//				}
//			}
//			for(int i=1;i<=m;i++){
//				for(int j=1;j<=n;j++){
//					ay[j][i]=ay[j-1][i]+mp[j][i];
//				}
//			}
			
		}
	}
	return 0;
}
/*
1 0
4 3 1 1
001
010
000
000
*/