#include <bits/stdc++.h>

constexpr int P = 998244353;

int main() {
  std::ifstream fin("plant.in");
  std::ofstream fout("plant.out");

  int T, id;
  fin >> T >> id;
  while (T--) {
    int n, m, c, f;
    fin >> n >> m >> c >> f;
    std::vector<std::string> a(n);
    for (int i = 0; i < n; ++i) {
      fin >> a[i];
    }
    std::vector<std::vector<int>> d(n, std::vector<int>(m));
    for (int i = n - 1; i >= 0; --i) {
      for (int j = 0; j < m; ++j) {
        if (a[i][j] == '0') {
          d[i][j] = (i + 1 < n ? d[i + 1][j] : 0) + 1;
        }
      }
    }
    std::vector<std::vector<int>> r(n, std::vector<int>(m));
    for (int i = 0; i < n; ++i) {
      for (int j = m - 1; j >= 0; --j) {
        if (a[i][j] == '0') {
          r[i][j] = (j + 1 < m ? r[i][j + 1] : 0) + 1;
        }
      }
    }
    std::vector<std::vector<int>> sum(n + 1, std::vector<int>(m));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        sum[i + 1][j] = sum[i][j] + r[i][j] - 1;
      }
    }
    std::vector<std::vector<int>> sumi(n + 1, std::vector<int>(m));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        sumi[i + 1][j] = sumi[i][j] + (r[i][j] - 1) * i;
      }
    }
    int ansC = 0, ansF = 0;
    for (int i = 0; i < n - 2; ++i) {
      for (int j = 0; j < m; ++j) {
        if (r[i][j] > 1 && d[i][j] > 1) {
          int s = sum[i + d[i][j]][j] - sum[i + 2][j];
          ansC = (ansC + 1ll * (r[i][j] - 1) * s) % P;
          int t = s * (i + d[i][j] - 1) - sumi[i + d[i][j]][j] + sumi[i + 2][j];
          ansF = (ansF + 1ll * (r[i][j] - 1) * t) % P;
        }
      }
    }
    fout << c * ansC << " " << f * ansF << "\n";
  }
}
