#include <bits/stdc++.h>
using namespace std;
template <typename X>
ostream& operator<<(ostream& x, const vector<X>& v) {
  for (long long i = 0; i < v.size(); ++i) x << v[i] << " ";
  return x;
}
template <typename X>
ostream& operator<<(ostream& x, const set<X>& v) {
  for (auto it : v) x << it << " ";
  return x;
}
template <typename X, typename Y>
ostream& operator<<(ostream& x, const pair<X, Y>& v) {
  x << v.ff << " " << v.ss;
  return x;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << "=>" << it.second << endl;
  return os;
}
struct pair_hash {
  inline std::size_t operator()(
      const std::pair<long long, long long>& v) const {
    return v.first * 31 + v.second;
  }
};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    string s[n];
    for (long long i = 0; i < n; i++) {
      cin >> s[i];
    };
    y = min(y, 2 * x);
    int ans = 0;
    for (long long i = 0; i < n; i++) {
      int j = 0;
      while (j < m) {
        if (s[i][j] == '*') {
          j++;
          continue;
        }
        int k = j;
        int cnt = 0;
        while (s[i][k] == '.') {
          k++;
          cnt++;
          if (k == m) {
            break;
          }
        }
        j = k;
        ans += (cnt / 2) * (y) + (cnt % 2) * x;
      }
    }
    cout << ans << endl;
  }
}
