#include<bits/stdc++.h>
//wo zhong wen shu ru fa ne ??
//xiang bu chu lai le
//fa dian!!!!
//ji shi xu yao qu mo,na ye shi guang ming!!!!
//qu mo wo hen si ni le
//shui jia da an shi 114514 a??
//chu ti ren shi ye shou xian bei ba(ban nao)
//wo zen me jue de ccf de yang li you wen ti a
//bu xing le yang li 2 zen me mo dou shi 8 ge f a
//che di beng kui
using namespace std;
typedef long long ll;
const int mod=998244353,N=1005;
int gar[N][N],zero[N][N];
int t,n,m,c,f,id;
ll ansc,ansf;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	scanf("%d%d",&t,&id);
	while(t--){
		scanf("%d%d%d%d",&n,&m,&c,&f);
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				char c;
				cin>>c;
				gar[i][j]=(c=='0')?0:1;
			}
		}
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=m;j++){
//				cout<<gar[i][j]<<" ";
//			}
//			cout<<endl;
//		}
		for(int i=1;i<=n;i++){
			for(int j=m;j>=1;j--){
				if(gar[i][j]==1) zero[i][j]=0;
				else zero[i][j]=zero[i][j+1]+1;
			}
		}
//		for(int i=1;i<=n;i++){
//			for(int j=1;j<=m;j++){
//				cout<<zero[i][j]<<" ";
//			}
//			cout<<endl;
//		}
		for(int j=1;j<=m;j++){
			int now=1,cnt=0;
//			cout<<"lieshu:"<<j<<endl;
			while(now<=n-2){
				if(gar[now][j]==1||gar[now+1][j]==1){
					while(gar[now][j]==1||gar[now+1][j]==1) now++;
				}
//				cout<<"hangshu:"<<now<<endl;
				for(int i=now+2;i<=n;i++){
					if(gar[i][j]==1) break;
					ansc=(ansc+(zero[now][j]-1)*(zero[i][j]-1)%mod)%mod;
//					cout<<"xian zai c de ge shu:"<<ansc<<endl;
					if(i<n&&((zero[now][j]-1)*(zero[i][j]-1))!=0&&gar[i+1][j]==0){
//						cout<<"f ok"<<endl;
						ansf=(ansf+(zero[now][j]-1)*(zero[i][j]-1)%mod)%mod;
						int rp=i+2;
						while(rp<=n&&gar[rp++][j]==0) ansf++;
					}
//					cout<<ansc<<" "<<ansf<<endl;
				}
				now++;
			}
		}
		if(!c) ansc=0;
		if(!f) ansf=0;
		cout<<ansc<<" "<<ansf<<endl;
	}
	return 0;
}