#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, x, y, ans = 0;
  cin >> n >> m >> x >> y;
  char a[n][m + 1];
  int cnt1 = 0, c2 = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m;) {
      if (a[i][j] == '.' && a[i][j - 1] == '.') {
        cnt1++;
        j += 2;
      } else
        j++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.') c2++;
    }
  }
  int gg = c2 - 2 * cnt1;
  if (2 * x <= y)
    ans = x * c2;
  else
    ans = y * cnt1 + gg * x;
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
