#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN = 1023;
const ll MOD = 998244353;
ll t, id;
ll n, m, c, f;
char mp[MAXN][MAXN];
ll nxt[MAXN][MAXN];
ll pre[MAXN][MAXN];
bool inited = false;
void init() {
  if (inited) return;
  for (int i = 1; i <= n; ++i) {
    nxt[i][m + 1] = -1;
    for (int j = m; j >= 1; --j) {
      if (mp[i][j] == '1')
        nxt[i][j] = -1;
      else
        nxt[i][j] = nxt[i][j + 1] + 1;
#ifdef DEBUG
      printf("%lld ", nxt[i][j]);
#endif
    }
#ifdef DEBUG
    printf("\n");
#endif
  }
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= n; ++i) {
      pre[i][j] = (pre[i - 1][j] + nxt[i][j]) % MOD;
    }
  }
  inited = true;
}
ll getVc() {
  static ll l, r;
  static ll valc = 0;
  init();
  for (int j = 1; j <= m; ++j) {
    l = r = 0;
    for (int i = 1; i <= n; ++i) {
      if (mp[i][j] == '1') {
        if (r - l + 1 >= 3) {
          for (int k = l + 2; k <= r; ++k) {
            valc = (valc +
                    nxt[k][j] *
                        (((pre[k - 2][j] - pre[l - 1][j]) % MOD + MOD) % MOD) %
                        MOD) %
                   MOD;
          }
        }
        l = r = 0;
      } else if (l == 0) {
        l = r = i;
      } else {
        r = i;
      }
    }
    if (l != 0 && r != 0) {
      if (r - l + 1 >= 3) {
        for (int k = l + 2; k <= r; ++k) {
          valc = (valc +
                  nxt[k][j] *
                      (((pre[k - 2][j] - pre[l - 1][j]) % MOD + MOD) % MOD) %
                      MOD) %
                 MOD;
        }
      }
      l = r = 0;
    }
  }
  return valc;
}
ll getVf() {
  static ll l, r;
  static ll valc = 0;
  init();
  for (int j = 1; j <= m; ++j) {
    l = r = 0;
    for (int i = 1; i <= n; ++i) {
      if (mp[i][j] == '1') {
        if (r - l + 1 >= 4) {
          for (int k = l + 2; k <= r - 1; ++k) {
            valc = (valc +
                    nxt[k][j] *
                        (((pre[k - 2][j] - pre[l - 1][j]) % MOD + MOD) % MOD) %
                        MOD * (r - k) % MOD) %
                   MOD;
          }
        }
        l = r = 0;
      } else if (l == 0) {
        l = r = i;
      } else {
        r = i;
      }
    }
    if (l != 0 && r != 0) {
      if (r - l + 1 >= 4) {
        for (int k = l + 2; k <= r - 1; ++k) {
          valc = (valc +
                  nxt[k][j] *
                      (((pre[k - 2][j] - pre[l - 1][j]) % MOD + MOD) % MOD) %
                      MOD * (r - k) % MOD) %
                 MOD;
        }
      }
      l = r = 0;
    }
  }
  return valc;
}
int main() {
#ifndef DEBUG
  freopen("plant.in", "r", stdin);
  freopen("plant.out", "w", stdout);
#endif
  scanf("%lld%lld", &t, &id);
  while (t--) {
    inited = false;
    scanf("%lld%lld%lld%lld", &n, &m, &c, &f);
    for (int i = 1; i <= n; ++i) {
      scanf("%s", mp[i] + 1);
    }
    if (c == 0)
      printf("0 ");
    else
      printf("%lld ", c * getVc());
    if (f == 0)
      printf("0\n");
    else
      printf("%lld\n", f * getVf());
  }
  return 0;
}
/*
1 0
4 3 1 1
001
010
000
000
*/