#include<bits/stdc++.h>
using namespace std;
const int md=998244353;
int read()
{
    int x=0;bool f=0;char c=getchar();
    for(;!isdigit(c);c=getchar())f^=!(c-45);
    for(;isdigit(c);c=getchar())x=x*10+c-48;
    if(f)x=-x;return x;
}
int ti,id;
int n,m,cc,ff;
int b[1050][1050],a[1050];
char sa[1050];
signed main()
{
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    ti=read(),id=read();
    while(ti--)
    {
        memset(b,0,sizeof(b));
        n=read(),m=read(),cc=read(),ff=read();
        for(int i=1;i<=n;i++)
        {
            cin>>sa+1;
            for(int j=m;j>=1;j--)
            {
                if(sa[j]=='0')b[i][j]=b[i][j+1]+1;
            }
        }
        long long pr=0,ps=0,pc=0,pf=0;
        for(int j=1;j<=m;j++)
        {
            pr=ps=0;
            a[n+1]=0;
            for(int i=n;i>=1;i--)
            {
                if(b[i][j]!=0)
                {
                    a[i]=a[i+1]+1;
                }
                else a[i]=0;
            }
            for(int i=1;i<=n;i++)
            {
                if(b[i][j]==0)
                {
                    pr=ps=0;continue;
                }
                else
                {
                    pc=(pc+ps*(b[i][j]-1))%md;
                    pf=(pf+ps*(b[i][j]-1)*(a[i]-1))%md;
                    ps=(ps+pr)%md;
                    pr=(b[i][j]-1);
                }
            }
        }
        cout<<cc*pc%md<<" "<<ff*pf%md<<"\n";
    }
}