#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> v;
    for (int i = 0; i <= n - 1; i++) {
      string s;
      s.push_back('1');
      cin >> s;
      char curr = s[0];
      int currlen = 1;
      for (int j = 1; j <= m; j++) {
        if (s[j] == curr) {
          currlen++;
        } else {
          if (curr == '.') v.push_back(currlen);
          currlen = 1;
          curr = s[j];
        }
      }
    }
    int for2 = min(2 * x, y);
    int ans = 0;
    if (v.size() == 0) {
      cout << 0 << endl;
    } else {
      for (int i = 0; i <= v.size() - 1; i++) {
        if (v[i] % 2 == 1) {
          ans += for2 * (v[i] - 1) / 2 + x;
        } else {
          ans += for2 * v[i] / 2;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
