#include <stdio.h>
#include <algorithm>
#include <set>
#include <string.h>
#define int long long
int read()
{
    int x=0,f=1,c=getchar();
    while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
    while(c>47&&c<58)x=x*10+c-48,c=getchar();
    return x*f;
}
int re1d()
{
    int c=getchar();
    while(c<48||c>57)c=getchar();
    return c-48;
}
const int mod=998244353;
int a[1005][1005];
int c[1005][1005],f[1005][1005],R[1005][1005],C[1005][1005];
int ae(int x,int y){int z=x+y;if(z>=mod)z-=mod;return z;}
int me(int x,int y){return x*y%mod;}
signed main()
{
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    int T=read(),id=read();
    for(int tt=1;tt<=T;tt++)
    {
        int n=read(),m=read(),ac=read(),af=read();
        for(int i=0;i<=n+2;i++) 
            for(int j=0;j<=m+2;j++)
                c[i][j]=f[i][j]=R[i][j]=C[i][j]=0,a[i][j]=1;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                a[i][j]=re1d();
        int x=0,y=0;
        for(int i=n;i>=1;i--)
            for(int j=m;j>=1;j--)
            {
                if(a[i][j]==0)
                {
                    C[i][j]=ae(C[i][j+1],(a[i][j+1]==0));
                    R[i][j]=ae(R[i+1][j],(a[i+1][j]==0));
                    c[i][j]=ae(C[i][j],c[i+1][j]);
                    f[i][j]=ae(f[i+1][j],me(C[i][j],R[i][j]));
                    if(a[i+1][j]==0)
                        x=ae(x,me(C[i][j],c[i+2][j])),
                        y=ae(y,me(C[i][j],f[i+2][j]));
                }
            }
        printf("%lld %lld\n",me(ac,x),me(af,y));
    }
}