#include <bits/stdc++.h>
using namespace std;
const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 107;
void solve() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int cnt = 0;
  int mark[N][N * 10];
  memset(mark, 0, sizeof mark);
  string S[N];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
    for (int j = 0; j < m; j++) {
      if (S[i][j] == '.') ++cnt;
    }
  }
  if (2 * x <= y) {
    cout << 1LL * cnt * x << endl;
    return;
  }
  int single = 0, db = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (S[i][j] == '*' || mark[i][j]) continue;
      if (j + 1 == m || S[i][j + 1] == '*') {
        single++;
        mark[i][j]++;
        continue;
      }
      db++;
      mark[i][j]++;
      mark[i][j + 1]++;
    }
  }
  cout << ((1LL * single * x) + (1LL * db * y)) << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
