#include <bits/stdc++.h>
using namespace std;
void deepshit() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  deepshit();
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    long long cost = 0;
    for (long long i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (long long j = 0; j < m - 1; j++) {
        if (s[j] == '.' && s[j + 1] == '.') {
          cost += min(2 * x, y);
          s[j] = '*';
          s[j + 1] = '*';
        }
      }
      for (long long j = 0; j < m; j++) {
        if (s[j] == '.') {
          cost += x;
          s[j] = '*';
        }
      }
    }
    cout << cost << "\n";
  }
  return 0;
}
