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