#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
const long long mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
long long gcd(long long A, long long B) {
  if (B == 0) return A;
  return gcd(B, A % B);
}
long long lcm(long long A, long long B) { return A * B / gcd(A, B); }
int digits(long long m) {
  int re = 0;
  while (m > 0) {
    m /= 10;
    re++;
  }
  return re;
}
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<string> a(n);
    for (long long int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (j < m - 1 and a[i][j] == '.' and a[i][j + 1] == '.') {
          if (2 * x <= y) {
            ans += 2 * x;
          } else {
            ans += y;
          }
          j++;
        } else if (j < m - 1 and a[i][j] == '.' and a[i][j + 1] != '.') {
          ans += x;
          j++;
        } else if (j == m - 1 and a[i][j] == '.') {
          ans += x;
        }
      }
    }
    cout << ans << endl;
    t--;
  }
}
