#include<bits/stdc++.h>
using namespace std;
const int N=1005,mo=998244353;
char s[N];
int rig[N][N],dwn[N][N],a[N][N];
void _main(){
    int n,m,cc,ff;
    scanf("%d%d%d%d",&n,&m,&cc,&ff);
    for(int i=1;i<=n;i++){
        scanf("%s",s+1);
        for(int j=1;j<=m;j++){
            a[i][j]=s[j]=='1';
        }
    }
    for(int i=n;i>=1;i--){
        for(int j=m;j>=1;j--){
            if(a[i][j]==0){
                rig[i][j]=max(rig[i][j+1]+1,0);
                dwn[i][j]=max(dwn[i+1][j]+1,0);
            }
        }
    }
    /*
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cout<<rig[i][j]<<' ';
        }
        cout<<endl;
    }



    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cout<<dwn[i][j]<<' ';
        }
        cout<<endl;
    }
    */
    int ansc=0,ansf=0;
    for(int j=1;j<=m;j++){
        int sumT=0;
        for(int i=1;i<=n;i++){
            if(a[i][j]==1){
                sumT=0;
            }
            else{
                ansc=(ansc+1ll*(rig[i][j]-1)*sumT%mo)%mo;
                ansf=(ansf+1ll*(rig[i][j]-1)*sumT%mo*(dwn[i][j]-1)%mo);
                if(rig[i-1][j]>0)sumT+=(rig[i-1][j]-1);
                //cout<<i<<" "<<j<<' '<<sumT<<endl;
                //cout<<ansc<<" "<<ansf<<endl<<endl;
            }
        }
    }
    printf("%lld %lld\n",1ll*cc*ansc%mo,1ll*ff*ansf%mo);
}
int main(){
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    int T,id;
    scanf("%d%d",&T,&id);
    for(int i=1;i<=T;i++){
        _main();
    }
}
