#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int infi = INT_MAX;
const long long infll = LLONG_MAX;
const long double PI = 3.1415926535897932384626;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
long long pow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % m;
    }
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      return false;
    }
  return true;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long lcm(long long a, long long b) { return ((a / gcd(a, b)) * b); }
void solve(int test_case) {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<string> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m;) {
      if (v[i][j] == '*') {
        ++j;
        continue;
      }
      if (v[i][j] == '.' && v[i][j + 1] != '.') {
        ans += x;
        ++j;
        continue;
      }
      if (v[i][j + 1] == v[i][j] && v[i][j] == '.') {
        if (y < 2 * x) {
          ans += y;
        } else {
          ans += 2 * x;
        }
        j += 2;
        continue;
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    solve(tc);
  }
  return 0;
}
