// This Code was made by Chinese_zjc_.
#include <bits/stdc++.h>
const int MOD = 998244353;
struct mint
{
    unsigned v;
    mint(unsigned v_ = 0) : v(v_) {}
    mint &operator+=(const mint &X) { return (v += X.v) >= MOD ? v -= MOD : v, *this; }
    mint &operator-=(const mint &X) { return (v += MOD - X.v) >= MOD ? v -= MOD : v, *this; }
    mint &operator*=(const mint &X) { return v = 1llu * v * X.v % MOD, *this; }
    mint &operator/=(const mint &X) { return *this *= X.inv(); }
    mint pow(long long B) const
    {
        B %= MOD - 1;
        if (B < 0)
            B += MOD - 1;
        mint res = 1, A = *this;
        while (B)
        {
            if (B & 1)
                res *= A;
            A *= A;
            B >>= 1;
        }
        return res;
    }
    mint inv() const { return pow(MOD - 2); }
    friend mint operator+(const mint &A, const mint &B) { return mint(A) += B; }
    friend mint operator-(const mint &A, const mint &B) { return mint(A) -= B; }
    friend mint operator*(const mint &A, const mint &B) { return mint(A) *= B; }
    friend mint operator/(const mint &A, const mint &B) { return mint(A) /= B; }
    friend std::istream &operator>>(std::istream &A, mint &B) { return A >> B.v; }
    friend std::ostream &operator<<(std::ostream &A, const mint &B) { return A << B.v; }
    friend bool operator==(const mint &A, const mint &B) { return A.v == B.v; }
    explicit operator bool() const { return v; }
} c, f, ansc, ansf;
char a[1005][1005];
int T, id, n, m, R[1005][1005], D[1005][1005];
signed main()
{
    freopen("plant.in", "r", stdin) && freopen("plant.out", "w", stdout);
    std::ios::sync_with_stdio(false);
    std::cin >> T >> id;
    while (T--)
    {
        std::memset(a, 0, sizeof(a));
        std::memset(R, 0, sizeof(R));
        std::memset(D, 0, sizeof(D));
        std::cin >> n >> m >> c >> f;
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= m; ++j)
                std::cin >> a[i][j];
        for (int i = 1; i <= n; ++i)
            for (int j = m; j; --j)
                R[i][j] = a[i][j] == '0' ? R[i][j + 1] + 1 : 0;
        for (int i = n; i; --i)
            for (int j = 1; j <= m; ++j)
                D[i][j] = a[i][j] == '0' ? D[i + 1][j] + 1 : 0;
        ansc = ansf = 0;
        for (int i = 1; i <= m; ++i)
        {
            mint sum1 = 0, sum2 = 0;
            for (int j = n; j; --j)
                if (a[j][i] == '0')
                {
                    if (R[j - 1][i])
                    {
                        ansc += sum1 * (R[j - 1][i] - 1);
                        ansf += sum2 * (R[j - 1][i] - 1);
                    }
                    sum1 += (R[j][i] - 1);
                    sum2 += (D[j][i] - 1) * (R[j][i] - 1);
                }
                else
                    sum1 = sum2 = 0;
        }
        std::cout << ansc * c << ' ' << ansf * f << std::endl;
    }
    return 0;
}