#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll rd(){
    ll x = 0;bool f = true;char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')f = false;
        c = getchar();
    }
    while(c <= '9' && c >= '0'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return f ? x : -x;
}

const int N = 1e3 + 10;
const int mod = 998244353;

int T, n, m;
ll c, f, tc, tf;
char a[N][N];
int cnt;
int r[N][N], down[N][N];
ll dp[N][N][3];

void add(ll &x, ll y){
    x = x + y < mod ? x + y : x + y - mod;
    return;
}

int main(){
    // freopen("E:/test/test.in", "r", stdin);
    // freopen("E:/test/test.out", "w", stdout);

    // freopen("E:/test/test.in", "r", stdin);
    // freopen("E:/test/test.out", "w", stdout);
    freopen("plant.in", "r", stdin);
    freopen("plant.out", "w", stdout);
    T = rd();
    int id = rd();
    while(T--){
        memset(r, 0, sizeof(r));
        memset(dp, 0, sizeof(dp));
        memset(down, 0, sizeof(down));

        n = rd(), m = rd(), c = rd(), f = rd();
        for(int i = 1; i <= n; ++i)
            scanf("%s", a[i] + 1);

        for(int i = n; i >= 1; --i){
            for(int j = 1; j <= m; ++j){
                if(a[i][j] == '1')down[i][j] = 0;
                else down[i][j] = down[i + 1][j] + 1;
            }
        }
        for(int i = 1; i <= n; ++i){
            for(int j = m; j >= 1; --j){
                if(a[i][j] == '1')r[i][j] = 0;
                else r[i][j] = r[i][j + 1] + 1;
            }
        }

        // for(int i = 1; i <= n; ++i){
        //     for(int j = 1; j <= m; ++j){
        //         printf("%d", l[i][j]);
        //     }
        //     putchar(10);
        // }
        // putchar(10);
        // for(int i = 1; i <= n; ++i){
        //     for(int j = 1; j <= m; ++j){
        //         printf("%d", r[i][j]);
        //     }
        //     putchar(10);
        // }
        // putchar(10);
        // for(int i = 1; i <= n; ++i){
        //     for(int j = 1; j <= m; ++j){
        //         printf("%d", down[i][j]);
        //     }
        //     putchar(10);
        // }

        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= m; ++j){
                if(r[i][j] > 1)
                    dp[i][j][0] = r[i][j] - 1;
                if(a[i][j] == '1')continue;
                add(dp[i][j][1], dp[i - 1][j][1]);
                add(dp[i][j][1], dp[i - 1][j][0]);
                if(r[i][j] > 1)
                    dp[i][j][2] = dp[i - 1][j][1] * (r[i][j] - 1) % mod;
            }
        }

        tc = 0, tf = 0;
        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= m; ++j){

                // printf("%d ", dp[i][j][2]);
                add(tc, dp[i][j][2]);
                if(down[i][j] > 1)
                    add(tf, dp[i][j][2] * (down[i][j] - 1) % mod);
                    
                
            }
            // putchar(10);
        }
        tc = tc * c % mod;
        tf = tf * f % mod;
        printf("%lld %lld\n", tc, tf);



    }
    return 0;
}