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

const int P = 998244353;
inline void add(int &x, int y) { (x += y) >= P && (x -= P); }
inline int Add(int x, int y) { return add(x, y), x; }
inline void mul(int &x, int y) { x = 1ll * x * y % P; }
inline int Mul(int x, int y) { return 1ll * x * y % P; }

template<typename T>
inline void read(T &x) {
    x = 0; char ch = getchar();
    bool f = 0;
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    if (f) x = -x;
}

const int N = 1005;
int n, m, c, f, rp[N][N];
char s[N][N];

void solve() {
    read(n), read(m), read(c), read(f);
    for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
    for (int i = 1; i <= n; ++i) {
        rp[i][m + 1] = 0;
        for (int j = m; j >= 1; --j) 
            rp[i][j] = (s[i][j] == '0') ? (rp[i][j + 1] + 1) : 0; 
    }

    int ans1 = 0, ans2 = 0;
    for (int j = 1; j <= m; ++j) {
        for (int l = 1, r; l <= n; l = r + 1) {
            r = l;
            if (s[l][j] == '1') continue;
            while (r < n && s[r + 1][j] == '0') ++r;
            int sum1 = 0, sum2 = 0;
            for (int i = r - 2; i >= l; --i) {
                add(sum1, rp[i + 2][j] - 1);
                add(sum2, Mul(rp[i + 2][j] - 1, r - i - 2));
                add(ans1, Mul(rp[i][j] - 1, sum1));
                add(ans2, Mul(rp[i][j] - 1, sum2));
            }
        }
    }
    printf("%d %d\n", c * ans1, f * ans2);
}

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

    int T, id; read(T), read(id);
    while (T--) solve();

    return 0;
}