#include<bits/stdc++.h>
using namespace std;
const int Mod=998244353;
int T,id;
char Getchar(){
    static char now[1<<20],*S,*T;
    if (T==S){
        T=(S=now)+fread(now,1,1<<20,stdin);
        if (T==S) return EOF;
    }
    return *S++;
}
int read(){
    int x=0,f=1;
    char ch=Getchar();
    while (ch<'0'||ch>'9'){
        if (ch=='-') f=-1;
        ch=Getchar();
    }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=Getchar();
    return x*f;
}
int read01(){
    char ch=Getchar();
    while (ch<'0'||ch>'1') ch=Getchar();
    return ch-'0';
}
int n,m,c,f,a[1100][1100];
int U[1100][1100],D[1100][1100],R[1100][1100];
bool checkr(int x,int yl,int yr){
    for (int i=yl;i<=yr;i++)
        if (!a[x][i]) return false;
    return true;
}
bool checkc(int y,int xl,int xr){
    for (int i=xl;i<=xr;i++)
        if (!a[i][y]) return false;
    return true;
}
int main(){
    freopen("plant.in","r",stdin);
    freopen("plant.ans","w",stdout);
    T=read(); id=read();
    while (T--){
        n=read(); m=read(); c=read(); f=read();
        for (int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
                a[i][j]=(read01()^1);
        int ans1=0,ans2=0;
        for (int x1=1;x1<=n;x1++)
            for (int x2=x1+2;x2<=n;x2++)
                for (int y0=1;y0<=m;y0++)
                    for (int y1=y0+1;y1<=m;y1++)
                    for (int y2=y0+1;y2<=m;y2++)
                        if (checkr(x1,y0,y1)&&checkr(x2,y0,y2)&&checkc(y0,x1,x2)){
                            ans1++;
                        }
        for (int x1=1;x1<=n;x1++)
            for (int x2=x1+2;x2<=n;x2++)
            for (int x3=x2+1;x3<=n;x3++)
                for (int y0=1;y0<=m;y0++)
                    for (int y1=y0+1;y1<=m;y1++)
                    for (int y2=y0+1;y2<=m;y2++)
                        if (checkr(x1,y0,y1)&&checkr(x2,y0,y2)&&checkc(y0,x1,x3)){
                            ans2++;
                        }
        cout<<ans1*c<<' '<<ans2*f<<'\n';
    }
    return 0;
}
