#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int md=998244353;
string s;
ll T,Id,n,m,c,f,a[1001][1001],r[1001][1001],low[1001][1001],vc=0,vf=0;
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	cin>>T>>Id;
	while(T--){
		vc=0,vf=0;;
		cin>>n>>m>>c>>f;
		memset(a,0,sizeof(a));
		memset(r,0,sizeof(r));
		memset(low,0,sizeof(low));
		for(int i=1;i<=n;i++){
			cin>>s;
			for(int j=0;j<m;j++){
				if(s[j]=='1'){
					a[i][j+1]=1;
				}
				else{
					a[i][j+1]=0;
				}
			}
		}
		for(int i=1;i<=n;i++){
			int mr=0;
			for(int j=m;j>=1;j--){
				if(a[i][j]!=0){
					r[i][j]=0;
					mr=0;
			    }
			    else{
			    	if(mr==0){
			    		mr=j;
					}
					r[i][j]=mr;
				}
			}
		}
		for(int j=1;j<=m;j++){
			int ml=0;
			for(int i=n;i>=1;i--){
				if(a[i][j]!=0){
					low[i][j]=0;
					ml=0;
				}
				else{
					if(ml==0){
						ml=i;
					}
					low[i][j]=ml;
				}
			}
		}
		for(int i=1;i<=n-2;i++){
			for(int j=1;j<=m-1;j++){
				ll ttk=0;
				if(low[i][j]-i>=2){
					for(int k=i+2;k<=low[i][j];k++){
						ttk=(1ll*(r[i][j]-j)*(r[k][j]-j))%md;//problem
						vc=(vc+ttk)%md;
						if(k<low[i][j]){
							vf=(vf+(1ll*ttk*(low[i][j]-i-2))%md)%md;
						}
					}
				}
			}
		}
		vc=(c*vc)%md;
		vf=(f*vf)%md;
		cout<<vc<<' '<<vf<<endl;
	}
	
}
