//i love myself
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int gin() {
    int s=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9') {
        s=(s<<3)+(s<<1)+(c^48);
        c=getchar();
    }
    return s*f;
}

const int N=1005,mod=998244353;
// int n,m,c,f;
int R[N][N],D[N][N],RD[N][N],Sr[N][N],Srd[N][N];
char a[N][N];

signed main() {
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    int T=gin(),ID=gin();
    while(T--) {
        memset(R,0,sizeof(R));
        memset(D,0,sizeof(D));
        memset(RD,0,sizeof(RD));
        memset(Sr,0,sizeof(Sr));
        memset(Srd,0,sizeof(Srd));
        int n=gin(),m=gin(),c=gin(),f=gin();
        for(int i=1;i<=n;i++) {
            scanf("%s",a[i]+1);
        }
        for(int i=1;i<=n;i++) {
            int res=0;
            for(int j=m;j>=1;j--) {
                if(a[i][j]=='0') {
                    R[i][j]=res++;
                }
                else R[i][j]=res=0;
            }
        }
        for(int j=1;j<=m;j++) {
            int res=0;
            for(int i=n;i>=1;i--) {
                if(a[i][j]=='0') {
                    D[i][j]=res++;
                }
                else D[i][j]=res=0;
            }
        }
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=m;j++) {
                if(a[i][j]=='0') RD[i][j]=R[i][j]*D[i][j]%mod;
            }
        }
        for(int j=1;j<=m;j++) {
            for(int i=n;i>=1;i--) {
                if(a[i][j]=='1') {
                    Sr[i][j]=Srd[i][j]=0;
                    continue;
                }
                Sr[i][j]=(Sr[i+1][j]+R[i][j])%mod;
                Srd[i][j]=(Srd[i+1][j]+RD[i][j])%mod;
            }
        }
        int C=0,F=0;
        for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) {
            if(a[i+1][j]=='1') continue;
            C=(C+R[i][j]*Sr[i+2][j])%mod;
            F=(F+R[i][j]*Srd[i+2][j])%mod;
        }
        printf("%lld %lld\n",c*C%mod,f*F%mod);
        // for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) printf("%lld ",Sr[i][j]);
    }
    return 0;
}