#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353
#define N 1005
ll ans_1[N][N],ans_2[N][N],ans_3[N][N];
ll a[N][N],ans,T,id;
ll read()
{
    ll ans=0,f_id=1;
    char ch=getchar();
    while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if (ch=='-') f_id=-1,ch=getchar();
    while (ch>='0'&&ch<='9') ans=ans*10+ch-'0',ch=getchar();
    return ans*f_id;
}
ll read1()
{
    char ch=getchar();
    while ((ch!='0')&&(ch!='1')) ch=getchar();
    if (ch=='1') return 1;
    return 0;
}
int main()
{
    freopen("plant.in","r",stdin);freopen("plant.out","w",stdout);
    T=read(),id=read();
    while (T)
    {
        T--;
        ll n=read(),m=read(),c=read(),f=read(),ans=0;
        for (int i=1;i<=n;++i)
        for (int j=1;j<=m;++j)
        {
            a[i][j]=read1();
            ans_1[i][j]=0;
            ans_2[i][j]=0;
            ans_3[i][j]=0;
        }
        
        //cout<<n<<m<<endl;
        
        if (c==0 && f==0)
        {
            cout<<"0 0"<<endl;
            continue;
        }
        for (int i=1;i<=n;++i)
        {
            ans_1[i][m]=0;
            for (int j=m-1;j;--j)
            {
                if (a[i][j]==1 || a[i][j+1]==1) ans_1[i][j]=0;else
                    ans_1[i][j]=ans_1[i][j+1]+1;
            }
        }
        for (int j=1;j<=m;++j)
        {
            ans_2[n][j]=0;
            for (int i=n-1;i;--i)
            {
                if (a[i][j]==1 || a[i+1][j]==1) ans_2[i][j]=0;else
                    ans_2[i][j]=ans_2[i+1][j]+1;
            }
        }

        ans=0;
        for (int i=1;i<=n;++i)
        {
            for (int j=1;j<=m;++j)
            ans_3[i][j]=ans_3[i-1][j]+ans_1[i][j];
        }
        for (int i=1;i<=n-2;++i)
        for (int j=1;j<=m-1;++j)
        {
            if (a[i][j]==1 || ans_2[i][j]<2) continue;
            ans+=((ans_3[i+ans_2[i][j]][j]-ans_3[i+1][j])*ans_1[i][j]);
            ans%=mod;
        }
        ans%=mod;
        cout<<ans<<" ";
        if (f==0)
        {
            cout<<"0"<<endl;
            continue;
        }
        ans=0;
        for (int i=1;i<n;++i)
        for (int j=1;j<=m;++j)
        {
            if (a[i][j]==1 || a[i+1][j]==1 || ans_1[i][j]==0 || ans_2[i][j]==0) continue;
            ll anss=0;
            for (int k=i+2;k<=n;++k)
            {
                if (a[k][j]==1) break;
                anss+=(ans_1[k][j]*ans_2[k][j]);
                if (anss>=mod) anss-=mod;
            }
            anss=anss*ans_1[i][j];
            anss%=mod;
            ans+=anss;
            ans%=mod;
            //cout<<i<<" "<<j<<" "<<anss<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}

















