#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int ans = 0;
  char ch;
  if (x <= y / 2) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cin >> ch;
        if (ch == '.') {
          ans += x;
        }
      }
    }
    cout << ans << endl;
    return;
  }
  bool flag = false;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> ch;
      if (ch == '.') {
        if (flag) {
          ans += y;
          flag = false;
        } else {
          flag = true;
        }
      } else {
        if (flag) {
          ans += x;
        }
        flag = false;
      }
    }
    if (flag) {
      ans += x;
      flag = false;
    }
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
