#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  if (y > x * 2) y = x * 2;
  int ans = 0;
  while (n--) {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
      if (s[i] == '.') {
        if (i + 1 < m && s[i + 1] == '.') {
          ans += y;
          i++;
        } else {
          ans += x;
        }
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
}
