#include <bits/stdc++.h>
using namespace std;
long long ncr(long long N, long long r) {
  long long i, j;
  long long sol[N + 1][r + 1];
  for (i = 1; i <= N; i++) {
    sol[i][0] = 1;
    sol[i][i] = 1;
  }
  for (i = 2; i <= N; i++) {
    for (j = 1; j < i; j++) {
      sol[i][j] = sol[i - 1][j] + sol[i - 1][j - 1];
    }
  }
  return sol[N][r];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    char a[n][m];
    long long i, j;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    long long ans = 0, curr = 0;
    for (i = 0; i < n; i++) {
      curr = 0;
      for (j = 0; j < m; j++) {
        if (a[i][j] == '.') {
          curr++;
        }
        if ((a[i][j] == '*') || (j == (m - 1))) {
          if (y >= (2 * x)) {
            ans = ans + (curr * x);
            curr = 0;
          } else {
            ans = ans + (((curr % 2) * x) + ((curr / 2) * y));
            curr = 0;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
