#include <bits/stdc++.h>
using namespace std;
bool comp(int x, int y) { return x > y; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  int n, m, x, y;
  while (t--) {
    cin >> n >> m >> x >> y;
    string str;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> str;
      int j = 0;
      while (j < str.length()) {
        if (str[j] == '.') {
          if (j < str.length() - 1 && str[j + 1] == '.') {
            sum += min(2 * x, y);
            j += 1;
          } else {
            sum += x;
          }
        }
        j += 1;
      }
    }
    cout << sum << '\n';
  }
}
