#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,c,f;
unsigned ll ansc=0,ansf=0;
int const gm=1101,mmod=998244353;
bitset<gm> bi[gm];
int le[gm][gm];
int sle[gm][gm];
char cc[gm];
void ff(int x,int y){
	if(sle[x][y]<3 || le[x][y]<=1) return;
	//cout<<x<<" "<<y<<endl;
	int mxi=min(sle[x][y]+x-1,n);
	for(int i=x+2;i<=mxi;i++){
		ansc+=(le[x][y]-1)*(le[i][y]-1);
		ansc%=mmod;
		ansf+=(le[x][y]-1)*(le[i][y]-1)*sle[i+1][y];
		ansf%=mmod;
	}
}
int main(){
	freopen("plant.in","r",stdin);
	freopen("plant.out","w",stdout);
	int t,id;
	cin>>t>>id;
	while(t--){
		cin>>n>>m>>c>>f;
		for(int i=1;i<=n;i++){
			scanf("%s",cc+1);
			for(int j=1;j<=m;j++){
				bi[i][j]=(cc[j]=='0');
			}
		}
		for(int i=n;i>=1;i--){
			for(int j=m;j>=1;j--){
				if(bi[i][j]){
					sle[i][j]=sle[i+1][j]+1;
					le[i][j]=le[i][j+1]+1;
				}else{
					sle[i][j]=0;
					le[i][j]=0;
				}
			}
		}
		/*for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cout<<sle[i][j];
			}
			cout<<endl;
		}*/
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				ff(i,j);
			}
		}
	}
	ansc*=c;
	ansf*=f;
	ansc%=mmod;
	ansf%=mmod;
	cout<<ansc<<" "<<ansf<<endl;
	return 0;
}