#include<bits/stdc++.h>
using namespace std;

const int N = 1000 + 10, P = 998244353;
int T, id, n, m, c, f;
char g[N][N];
int kx[N][N];
long long C, F;

int get(int a[N][N], int x, int y, int X, int Y)
{
    if(x > X || y > Y) return 0;
    return a[X][Y] - a[x - 1][Y] - a[X][y - 1] + a[x - 1][y - 1];
}

int main(void)
{
    freopen("plant.in", "r", stdin);
    freopen("plant.out", "w", stdout);
    scanf("%d%d", &T, &id);
    while(T--)
    {
        scanf("%d%d%d%d", &n, &m, &c, &f);
        C = 0, F = 0;
        if(c == 0 && f == 0)
        {
            puts("0 0");
            continue;
        }
        for(int i = 1; i <= n; i++)
        {
            scanf("%s", g[i] + 1);
            // puts(g[i] + 1);
        }
        
        for(int i = 1; i <= n; i++)
        {
            int cnt = 0;
            for(int j = m; j >= 1; j--)
            {
                if(g[i][j] == '0')
                {
                    kx[i][j] = cnt;
                    // printf("kx[%d][%d] = %d\n", i, j, kx[i][j]);
                    cnt++;
                }
                else
                {
                    kx[i][j] = 0;
                    cnt = 0;
                }
            }
        }

        for(int j = 1; j <= m; j++)
        {
            long long cnt = 0;
            for(int i = n; i >= 1; i--)
            {
                if(g[i][j] == '1') {cnt = 0; continue;}
                if(cnt != 0 && kx[i][j])
                {
                    C += (long long)c * (kx[i][j]) * (cnt - kx[i + 1][j]);
                    C %= P;
                    // printf("%d, %d, C += %lld\n",i, j,  (long long) (kx[i][j]) * (cnt - kx[i + 1][j]));
                }
                cnt += kx[i][j];
            }
        }

        for(int j = 1; j <= m; j++)
        {
            long long cnt = 0, gog = 0;
            for(int i = n; i >= 1; i--)
            {
                if(g[i][j] == '1') {cnt = 0; gog = 0; continue;}
                if(cnt != 0 && kx[i][j])
                {
                    F += (long long)f * (kx[i][j]) * (cnt - kx[i + 1][j] * (gog - 1));
                    F %= P;
                    // printf("%d, %d, cnt = %lld, F += %lld\n",i, j,cnt,   (long long) (kx[i][j]) * (cnt - kx[i + 1][j] * (gog - 1)));
                }
                cnt += kx[i][j] * gog;
                gog++; // weiba
            }
        }

        printf("%lld %lld\n", C, F);
    }
}