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

namespace IO {
inline int read() {
    int x = 0, f = 0;
    char ch = getchar();
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
    return f ? -x : x;
}
template<typename T>
inline void write(T x) {
    static int stk[65], top;
    top = 0;
    if (x < 0) putchar('-'), x = -x;
    do {
        stk[++top] = x % 10;
        x /= 10;
    } while (x);
    while (top) {
        putchar(stk[top] + '0');
        top--;
    }
}
template<typename T>
inline void write(T x, char ch) {
    write(x), putchar(ch);
}
}

const int N = 1005;
const int mod = 998244353;

inline void addx(int &x, int y) {
    if ((x += y) >= mod) x -= mod;
}
inline int mul(int x, int y) {
    return 1ull * x * y % mod;
}

char a[N][N];
int L[N];
int n, m, c, f;

int ansc, ansf;

void sol1(int l, int r) {
    int cur1 = 0;
    for (int i = l; i <= r; i++) {
        if (i - 2 >= l) addx(cur1, L[i - 2] - 1);
        addx(ansc, mul(cur1, L[i] - 1));
        addx(ansf, mul(cur1, mul(L[i] - 1, r - i)));
    }
}

void solve() {
    n = IO::read(), m = IO::read(), c = IO::read(), f = IO::read();
    ansc = ansf = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%s", a[i] + 1);
        L[i] = 0;
    }
    for (int j = m; j >= 1; j--) {
        int las1 = 0;
        for (int i = 1; i <= n + 1; i++) {
            if (i == n + 1 || a[i][j] == '1') {
                sol1(las1 + 1, i - 1);
                las1 = i;
                L[i] = 0;
            }
            else L[i]++;
        }
    }
    printf("%d %d\n", c ? ansc : 0, f ? ansf : 0);
}

int main() {
    freopen("plant.in", "r", stdin);
    freopen("plant.out", "w", stdout);
    int T = IO::read(), id = IO::read();
    while (T--) solve();
    return 0;
}