#include<bits/stdc++.h>
using namespace std;
long long t,id,n,m,c,f,c1=0,f1=0;
char d[3005][3005];
int main(){
memset(d,0,sizeof(d));
cin>>t>>id;
for(int i=1;i<=t;i++){
cin>>n>>m>>c>>f;
for(int j=1;j<=n;j++){
for(int jj=1;jj<=m;jj++){
cin>>d[j][jj];
}
}
for(int k=1;k<n-1;k++){
for(int l=1;l<m;l++){
if(d[k][l]=='1'||d[k][l+1]=='1'||d[k+1][l]=='1'||d[k+2][l]=='1'||d[k+2][l+1]=='1') continue;
c1++;
for(int h=k+3;h<=n;h++){
if(d[h][l]=='0') f1++;
}
for(int l1=l+2;l1<=m;l1++){
if(d[k][l1]=='0'){
c1++;
for(int h=k+3;h<=n;h++){
if(d[h][l]=='0') f1++;
}
}
if(d[k+2][l1]=='0'){
c1++;
for(int h=k+3;h<=n;h++){
if(d[h][l]=='0') f1++;
}
}
}
for(int p=k+3;p<=n;p++){
if(d[p][l]=='0')
for(int l1=l+1;l1<=m;l1++){
if(d[p][l1]=='0'){
c1++;
for(int h=p+1;h<=n;h++){
if(d[h][l]=='0') f1++;
}
}
}
}
}
}
cout<<(c1*c)%998244353<<" "<<(f1*f)%998244353;
c1=0; f1=0;
cout<<endl;
}
return 0;
}