// 10:04
// 66~100 pts
// attention 512MB ！
//Kolomi_suki
#include <bits/stdc++.h>
using namespace std;
const long long momo=998244353; 
int T,id,c,f,n,m;
char mapp[1010][1010];
int kc[1010][1010];
long long ansc;
long long ansf;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>T>>id;
	while(T--){
		cin>>n>>m>>c>>f;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>mapp[i][j];
			}
		}
		if(c==0 and f==0){
			cout<<"0 0"<<endl;
			continue;
		}
		for(int i=1;i<=n;i++){
			int now=-1;
			for(int j=m;j>=1;j--){
				if(mapp[i][j]=='0'){
					now++;
					kc[i][j]=now;
				}
				else{
					now=-1;
					kc[i][j]=-1;
				}
			}
		}
		for(int i=1;i<=m;i++){//mei ju lie
			for(int j=1;j<=n-2;j++){//mei ju hang
				if(kc[j][i]==-1){//shi tou
					continue;
				}
				for(int k=j+1;k<=n;k++){//mei ju duiyinghang
					if(kc[k][i]==-1){// shitou
						break;
					}
					else if(k>=j+2){
						ansc+=(kc[j][i]*kc[k][i]);
						ansc%=momo;
						int cnt=0;
						for(int q=k+1;q<=n;q++){
							if(kc[q][i]==-1){//shi tou
								break;
							}
							cnt++;
						}
						ansf+=(kc[j][i]*kc[k][i]*cnt);
						ansf%=momo;
					}
				}
			}
		}
		cout<<ansc<<" "<<ansf<<endl; 
	}
	return 0;
}
