#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
const int _=1e3+10,p=998244353;
int t,id,n,m,a[_][_],oc,of,rr[_];
char ch[_];
struct fint{
    int v;
    fint(long long V=0){
        if(V%p==0&&V!=0)v=p;
        else v=V%p;
    }
};
#define OP operator
fint OP+ (fint U,fint V){return 1ll*U.v+V.v;}
fint OP* (fint U,fint V){return 1ll*U.v*V.v;}
fint OP+=(fint&U,fint V){return U=U+V;}
fint OP*=(fint&U,fint V){return U=U*V;}
fint r[_],c[_],f[_],cans,fans;
void fun(int x){
    for(int i=1;i<=n;i++){
        if(!a[i][x])
            rr[i]++;
        else 
            rr[i]=0;

        if(rr[i])
            r[i]=r[i-1]+max(0,rr[i-1]-1);
        else 
            r[i]=0;

        if(r[i-1].v&&rr[i])
            c[i]=r[i-1]*(rr[i]-1);
        else 
            c[i]=0;
        
        if(rr[i])
            f[i]=c[i-1]+f[i-1];
        else f[i]=0;
        cans+=c[i],fans+=f[i];
    }
}
void sol(){
    cin>>n>>m>>oc>>of,cans=fans=0;
    for(int i=1;i<=n;i++){
        cin>>(ch+1);
        for(int j=1;j<=m;j++)
            a[i][j]=(ch[j]=='1');
    }
    for(int i=m;i>=1;i--)
        fun(i);
    cout<<(cans*oc).v<<' '<<(fans*of).v<<endl;
}
int main(){
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>t>>id;
    while(t--)sol();
}