#include <iostream>
#include <string>
#include <cstring>
#define int long long

using namespace std;

const int MAXN=1010;
const int MOD=998244353;
int mp[MAXN][MAXN];
int fx[MAXN][MAXN];
int fy[MAXN][MAXN];
int sumy[MAXN][MAXN];

signed main()
{
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    ios::sync_with_stdio(false);
    int T,id;
    cin>>T>>id;
    while(T--)
    {
        memset(fx,0,sizeof(fx));
        memset(fy,0,sizeof(fy));
        memset(sumy,0,sizeof(sumy));
        int n,m,c,f;
        int ansc=0,ansf=0;
        cin>>n>>m>>c>>f;
        if((c==0 && f==0) || id==1)
        {
            cout<<"0 0"<<endl;
            continue;
        }
        for(int i=1;i<=n;i++)
        {
            string ss;
            cin>>ss;
            for(int j=1;j<=m;j++)
                mp[i][j]=ss[j-1]-'0';
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=m;j>=1;j--)
            {
                if(j==m || mp[i][j+1]==1 || mp[i][j]==1)
                    fx[i][j]=0;
                else
                    fx[i][j]=fx[i][j+1]+1;
            }
        }
        for(int j=1;j<=m;j++)
        {
            for(int i=n;i>=1;i--)
            {
                if(i==n || mp[i+1][j]==1 || mp[i][j]==1)
                    fy[i][j]=0;
                else
                    fy[i][j]=fy[i+1][j]+1;
            }
        }
        for(int j=1;j<=m-1;j++)
        {
            for(int i=1;i<=n;i++)
            {
                if(i==1)
                    sumy[i][j]=fx[i][j];
                else
                    sumy[i][j]=sumy[i-1][j]+fx[i][j];

            }
        }
        for(int i=1;i<=n-2;i++)
            for(int j=1;j<=m-1;j++)
            {
                if(mp[i][j] || fx[i][j]==0)
                    continue;
                for(int ii=i+2;ii<=min(n,i+fy[i][j]);ii++)
                {
                    if(mp[ii][j])
                        continue;
                    ansc=(ansc+fx[i][j]*fx[ii][j])%MOD;
                    ansf=(ansf+fx[i][j]*( sumy[ii-1][j]-sumy[i+1][j]) )%MOD;
                }
            }
        cout<<ansc<<' '<<ansf<<endl;
        /*
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
                cout<<fx[i][j]<<' ';
            cout<<endl;
        }
        cout<<endl;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
                cout<<sumy[i][j]<<' ';
            cout<<endl;
        }*/
    }
}//76 points,perhaps.
