#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005,mod=998244353;
int T,id,a[N][N],dis1[N][N],dis2[N][N],n,m,c,f,cnt;
vector<int> vc[N],vr[N],nxt[N];
ll ans1,ans2;
bool okc[N],okf[N];
int main()
{
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    cin>>T>>id;
    while(T--)
    {
        scanf("%d%d%d%d",&n,&m,&c,&f);
        ans1=ans2=cnt=0;
        for(int i=1;i<=n;i++)
            vc[i].clear(),vr[i].clear(),okc[i]=okf[i]=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                scanf("%1d",&a[i][j]);
                if(a[i][j]) vc[i].push_back(j);
            }
            vc[i].push_back(m+1);
        }
        if(!c&&!f)
        {
            printf("0 0\n");
            continue;
        }
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
                if(a[j][i]) vr[i].push_back(j);
            vr[i].push_back(n+1);
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            {
                int k=lower_bound(vc[i].begin(),vc[i].end(),j)-vc[i].begin();
                dis1[i][j]=vc[i][k]-j;
            }
        for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
            {
                int k=lower_bound(vr[i].begin(),vr[i].end(),j)-vr[i].begin();
                dis2[j][i]=vr[i][k]-j;
                if(dis2[j][i]>2)
                {
                    okc[i]=1;
                    if(dis2[j][i]>3) okf[i]=1;
                }
            }
        for(int i=1;i<m;i++)
        {
            if(!okc[i]) continue;
            for(int j=1;j<=n;j++)
            {
                if(dis2[j][i]<3||dis1[j][i]<2) continue;
                int num=dis1[j][i]-1;
                for(int z=j+2;z<=n&&dis2[z][i];z++)
                {
                    if(dis1[z][i]<2) continue;
                    ans1+=max(0LL,1LL*(dis1[z][i]-1)*num);
                    if(ans1>mod) ans1-=mod;
                }
            }
        }
        if(!f)
        {
            printf("%lld 0\n",ans1);
            continue;
        }
        for(int i=1;i<m;i++)
        {
            if(!okf[i]) continue;
            for(int j=1;j<=n;j++)
            {
                if(dis2[j][i]<4||dis1[j][i]<2) continue;
                int num=dis1[j][i]-1;
                for(int z=j+2;z<=n&&dis2[z][i];z++)
                {
                    int num2=dis2[z][i]-1;
                    ans2+=max(0LL,1LL*(dis1[z][i]-1)*num*num2);
                    if(ans2>mod) ans2-=mod;
                }
            }
        }
        printf("%lld %lld\n",ans1,ans2);
    }
    return 0;
}