#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5,mod=998244353;
int f[N][N],g[N][N],C,F,n,m;
char a[N][N];
void Joseph_Stalin(){
    memset(f,0,sizeof(f));
    memset(g,0,sizeof(g));
    cin>>n>>m>>C>>F;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
    for(int j=m;j>=1;j--)
        for(int i=1;i<=n;i++)if(a[i][j]=='0')g[i][j]=g[i][j+1]+1;
    for(int i=n;i;i--)for(int j=1;j<=m;j++)if(a[i][j]=='0')f[i][j]=f[i+1][j]+1;
    int resC=0,resF=0;
    for(int j=1;j<=m;j++){
        int sum=0;
        for(int i=3;i<=n;i++){
            if(a[i][j]=='1'||a[i-1][j]=='1'||a[i-2][j]=='1'){
                sum=0;
                continue;
            }
            sum=(sum+g[i-2][j]-1)%mod;
            resC=(resC+1ll*(g[i][j]-1)*sum%mod)%mod;
            resF=(resF+1ll*(g[i][j]-1)*sum%mod*(f[i][j]-1)%mod)%mod;
        }
    }
    cout<<resC*C<<' '<<resF*F;
}
int _,__;
int main(){
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    ios::sync_with_stdio(0);
    cin>>_>>__;
    while(_--)Joseph_Stalin();
}
/*
more test
*/