#include<bits/stdc++.h>
#define poly vector<int>
#define ll long long 
#define pa pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define IOS ios::sync_with_stdio(false)
#define N 1005
#define mod 998244353
#define int ll
using namespace std;
int n,m,c,f;
int a[N][N],rt[N][N],dw[N][N],sc[N][N],sf[N][N];
void BellaKira()
{
    int ans=0,ans1=0;
    cin>>n>>m>>c>>f;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
        {
            char ch;
            cin>>ch;
            a[i][j]=ch-'0';
        }
    for (int i=1;i<=n;i++)
    {
        rt[i][m+1]=0;
        for (int j=m;j>=1;j--)
            if (a[i][j]) rt[i][j]=0;
            else rt[i][j]=rt[i][j+1]+1;
    }
    for (int j=1;j<=m;j++)
    {
        sc[n+1][j]=0;
        dw[n+1][j]=0;
        sf[n+1][j]=0;
        for (int i=n;i>=1;i--)
            if (a[i][j]) 
            {
                sc[i][j]=0;
                dw[n+1][j]=0;
            }
            else 
            {
                if (i+2<=n&&a[i+1][j]==0)
                {
                    ans=(ans+(rt[i][j]-1)*(sc[i+2][j])%mod)%mod;
                    ans1=(ans1+(rt[i][j]-1)*(sf[i+2][j])%mod)%mod;
                }
                dw[i][j]=dw[i+1][j]+1;
                sc[i][j]=(sc[i+1][j]+(rt[i][j]-1))%mod;
                sf[i][j]=(sf[i+1][j]+(rt[i][j]-1)*(dw[i][j]-1)%mod)%mod;
            }
    }
    ans=ans*c%mod;ans1=ans1*f%mod;
    cout<<ans<<' '<<ans1<<'\n';
}
signed main()
{
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    IOS && cin.tie(0);
    int T,id;
    cin>>T>>id;
    while (T--)
    {
        BellaKira();
    }
}