#include <bits/stdc++.h>
using namespace std;
bool sortpair(const pair<long long, long long> &a,
              const pair<long long, long long> &b) {
  if (a.first == b.first)
    return a.second < b.second;
  else
    return a.first < b.first;
}
bool cmpdec(long long a, long long b) { return a > b; }
long long t;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    string s;
    long long lk = 0;
    long long single = 0;
    for (int i = 0; i < n; i++) {
      cin >> s;
      for (int i = 0; i < m; i++) {
        if (s[i] == '.' && s[i + 1] == '.') {
          lk++;
          i++;
          continue;
        }
        if (s[i] == '.' && s[i + 1] != '.') {
          single++;
        }
      }
    }
    if (2 * x <= y) {
      cout << (lk * 2 + single) * x << "\n";
    } else {
      cout << lk * y + single * x << "\n";
    }
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
