#include <bits/stdc++.h>

namespace Mod {

template <typename Type, Type P, typename MulType>
class ModInt {
   public:
    Type x;
    using Self = ModInt<Type, P, MulType>;
    ModInt(int a = 0) : x(a) {}
    explicit operator Type() { return x; }
    friend inline Self operator+(Self a, Self b) { return (a.x += b.x) >= P ? a.x - P : a.x; }
    friend inline Self operator-(Self a, Self b) { return (a.x += b.x) >= P ? a.x - P : a.x; }
    friend inline Self operator*(Self a, Self b) { return MulType(a.x) * b.x % P; }
    friend inline Self &operator+=(Self &a, Self b) { return (a.x += b.x) >= P ? a.x -= P, a : a; }
    friend inline Self &operator-=(Self &a, Self b) { return (a.x += b.x) >= P ? a.x -= P, a : a; }
    friend inline Self &operator*=(Self &a, Self b) { return a = MulType(a.x) * b.x % P; }
    template <typename ExpType>
    inline Self Pow(ExpType Exp) {
        Self Base(*this), Ans(1);
        while (Exp) {
            if (Exp & 1) Ans *= Base;
            Base *= Base, Exp >>= 1;
        }
        return Ans;
    }
    inline Self Inv() { return Pow(P - 2); }
};

};

using MInt = Mod::ModInt<int, 998244353, long long>;

const int N = 1005;

MInt f[3][N][N];

std::string s[N];

int main() {
    freopen("plant.in", "r", stdin);
    freopen("plant.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    int T, id;
    std::cin >> T >> id;
    while (T--) {
        int n, m, cc, ff;
        std::cin >> n >> m >> cc >> ff;
        for (int i = 0; i < n; ++i) std::cin >> s[i];
        memset(f, 0, sizeof(f));
        for (int i = n - 1; i >= 0; --i) {
            for (int j = m - 1; j >= 0; --j) {
                if (s[i][j] == '0') f[0][i][j] = f[0][i][j + 1] + 1;
            }
        }
        for (int i = n - 2; i >= 0; --i) {
            for (int j = m - 1; j >= 0; --j) {
                if (s[i][j] == '0' && s[i + 1][j] == '0') f[1][i][j] = f[1][i + 1][j] + f[0][i + 1][j + 1];
            }
        }
        MInt Ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) Ans += (s[i][j] == '0') * f[1][i + 1][j] * f[0][i][j + 1];
        }
        std::cout << int(Ans * cc) << ' ';
        memset(f[1], 0, sizeof(f[1]));
        for (int i = n - 1; i >= 0; --i) {
            for (int j = 0; j < m; ++j) {
                if (s[i][j] == '0') f[1][i][j] = f[1][i + 1][j] + 1;
            }
        }
        for (int i = n - 2; i >= 0; --i) {
            for (int j = m - 1; j >= 0; --j) {
                if (s[i][j] == '0' && s[i + 1][j] == '0')
                    f[2][i][j] = f[2][i + 1][j] + f[0][i + 1][j + 1] * f[1][i + 2][j];
            }
        }
        Ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) Ans += (s[i][j] == '0') * f[0][i][j + 1] * f[2][i + 1][j];
        }
        std::cout << int(Ans) << '\n';
    }
    return 0;
}