#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+5, mod = 998244353;

int T,id;
int n,m,c,f,suf[N][N],pre[N],sf[N];
char mp[N][N];

int main() {
    freopen("plant.in","r",stdin);
    freopen("plant.out","w",stdout);
    scanf("%d%d",&T,&id);
    
    while (T--) {
        memset(suf,0,sizeof(suf));
        memset(pre,0,sizeof(pre));
        memset(sf,0,sizeof(sf));
        
        scanf("%d%d%d%d",&n,&m,&c,&f);
        for (int i = 1; i <= n; ++i) scanf("%s",mp[i]+1);

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

        int ansc = 0, ansf = 0;
        for (int j = 1; j <= m; ++j) {

            pre[0] = 0;
            for (int i = 1; i <= n; ++i) {
                if (mp[i][j] == '1') pre[i] = 0;
                else pre[i] = pre[i-1] + suf[i][j] - 1;
            }
            sf[n+1] = 0;
            for (int i = n; i >= 1; --i) {
                if (mp[i][j] == '1') sf[i] = 0;
                else sf[i] = sf[i+1]+1;
            }

            for (int i = 3; i <= n; ++i) {
                if (mp[i-1][j] == '1' || mp[i][j] == '1') continue;
                ansc += 1ll * (suf[i][j]-1) * pre[i-2] % mod;
                ansc %= mod;
                if (i == n || mp[i+1][j] == '1') continue;
                ansf += 1ll * (suf[i][j]-1) * pre[i-2] % mod * (sf[i+1]) % mod;
                ansf %= mod;
            }
        }
        printf("%d %d\n",ansc*c,ansf*f);

    }

    return 0;
}