// NOIP2022 RP++

#include <bits/stdc++.h>
typedef unsigned uint;
typedef unsigned long long ullt;typedef long long llt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _min(T&a,T b){return b<a?(a=b,true):false;}
template<typename T>bol _max(T&a,T b){return a<b?(a=b,true):false;}
const ullt Mod=998244353;
struct modint{
    ullt v;
    ullt&operator()(){return v;}
    modint():v(0){}
    modint(ullt v):v(v%Mod){}
    friend modint operator+(modint a,modint b){return a()+b();}
    friend modint operator-(modint a,modint b){return a()+Mod-b();}
    friend modint operator*(modint a,modint b){return a()*b();}
    voi read(){scanf("%llu",&v),v%=Mod;}
    voi print(){printf("%llu",v);}
    voi println(){print(),putchar('\n');}
    modint&operator+=(modint b){return*this=*this+b;}
};
uint A[1005][1005];
chr C[1005];
modint Rcnt[1005][1005];
voi solve(){
    uint n,m,c,f;
    scanf("%u%u%u%u",&n,&m,&c,&f);
    for(uint i=0;i<n;i++){
        scanf("%s",C);
        A[i][m]=1;for(uint j=0;j<m;j++)A[i][j]=C[j]=='1';
    }
    for(uint j=0;j<=m;j++)A[n][j]=1;
    for(uint i=0;i<n;i++)for(uint j=m-1;~j;j--)
        Rcnt[i][j]=A[i][j+1]?0:Rcnt[i][j+1]+1;
    modint ans;
    for(uint j=0;j<m;j++)
    {
        for(uint l=0,r;l<n;l=r){
            while(l<n&&A[l][j])l++;
            if(l==n)break;
            r=l;
            while(r<n&&!A[r][j])r++;
            modint sum;
            for(uint i=l+2;i<r;i++){
                sum+=Rcnt[i-2][j];
                ans+=sum*Rcnt[i][j];
            }
        }
    }
    (ans*c).print(),putchar(' ');
    ans=0;
    for(uint j=0;j<m;j++)
    {
        for(uint l=0,r;l<n;l=r){
            while(l<n&&A[l][j])l++;
            if(l==n)break;
            r=l;
            while(r<n&&!A[r][j])r++;
            modint sum;
            for(uint i=l+2;i<r;i++){
                sum+=Rcnt[i-2][j];
                ans+=sum*Rcnt[i][j]*(r-i-1);
            }
        }
    }
    (ans*f).println();
}
int main(){
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#else
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
#endif
    uint t;scanf("%u%*u",&t);
    while(t--)solve();
    return 0;
}

/*
g++ plant.cpp -o plant -DMYEE -Wall -std=c++11
biu#2019miss
solo@2022
*/
