#include<bits/stdc++.h>
using namespace std;
#define fo(v, a, b) for(int v = a; v <= b; v++)
#define fr(v, a, b) for(int v = a; v >= b; v--)
#define cl(a, v) memset(a, v, sizeof(a))

typedef long long ll;

const ll P = 998244353;
const int N = 1010;

int n, m, C, F, a[N][N]; char s[N];
int r[N][N]; ll c[N][N], f[N][N], ansC, ansF;

void Main() {
    scanf("%d%d%d%d", &n, &m, &C, &F);
    fo(i,1,n) {
        scanf("%s", s + 1);
        fo(j,1,m) a[i][j] = s[j] - '0';
    }

    cl(r, 0);
    fo(i,1,n) {
        r[i][m] = 0;
        fr(j,m-1,1) {
            r[i][j] = (a[i][j + 1] ? 0 : r[i][j + 1] + 1);
            if(a[i][j]) r[i][j] = 0;
        }
    }

    cl(c, 0), cl(f, 0), ansC = ansF = 0;
    fo(j,1,m) {
        ll cur = 0;
        fo(i,1,n) {
            if(a[i][j]) cur = 0;
            else {
                if(i >= 3 && a[i - 1][j] == 0)
                    cur = (cur + r[i - 2][j]) % P;
                c[i][j] = cur * r[i][j] % P;
            }
        }
    }
    fo(j,1,m) fo(i,1,n) if(a[i][j] == 0)
        f[i][j] = (f[i - 1][j] + c[i - 1][j]) % P;

    fo(i,1,n) fo(j,1,m) ansC = (ansC + c[i][j]) % P;
    fo(i,1,n) fo(j,1,m) ansF = (ansF + f[i][j]) % P;
    printf("%lld %lld\n", ansC * C % P, ansF * F % P);
}

int main()
{
    freopen("plant.in", "r", stdin);
    freopen("plant.out", "w", stdout);

    int T, Id; scanf("%d%d", &T, &Id);
    while(T--) Main();

    return 0;
}