#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0)) return false;
  }
  return true;
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    char a[n][m];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) cin >> a[i][j];
    }
    if (2 * x <= y) {
      long long sum = 0;
      for (long long i = 0; i < n; i++) {
        for (long long j = 0; j < m; j++) {
          if (a[i][j] == '.') sum += x;
        }
      }
      cout << sum << "\n";
    } else {
      long long sum = 0;
      for (long long i = 0; i < n; i++) {
        for (long long j = 1; j < m; j++) {
          if (a[i][j] == '.' && a[i][j - 1] == '.') {
            a[i][j] = '*';
            a[i][j - 1] = '*';
            sum += y;
          }
        }
        for (long long j = 0; j < m; j++)
          if (a[i][j] == '.') sum += x;
      }
      cout << sum << "\n";
    }
  }
}
