#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int kcz=998244353;
const int maxn=1005;
int n,m,r[maxn][maxn],c,f;
char s[maxn][maxn];
ll ansc,ansf,pre[4];
#define add(x,y) (((x+=(y))>=kcz)?x-=kcz:0)
int main()
{
    int T,i,j;
    freopen("plant.in","r",stdin),freopen("plant.out","w",stdout);
    scanf("%d%*d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&n,&m,&c,&f);
        for(i=0;i<n;i++)
            for(scanf("%s",s[i]),r[i][m]=m,j=m-1;j>=0;j--)
                r[i][j]=(s[i][j]=='1')?j:r[i][j+1];
        ansc=ansf=0;
        for(i=0;i<m;i++)
        {
            pre[0]=pre[1]=pre[2]=pre[3]=0;
            for(j=0;j<n;j++)
            {
                if(s[j][i]=='1') { pre[0]=pre[1]=pre[2]=pre[3]=0; continue; }
                add(pre[3],pre[2]),
                pre[2]=pre[1]*(ll)(r[j][i]-i-1)%kcz,
                add(pre[1],pre[0]),
                pre[0]=r[j][i]-i-1,
                add(ansc,pre[2]),add(ansf,pre[3]);
            }
        }
        printf("%lld %lld\n",c*ansc%kcz,f*ansf%kcz);
    }
    fclose(stdin),fclose(stdout);
    return 0;
}