#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int z = 0; z < t; z++) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    string s;
    int c = 0, d = 0;
    for (int i = 0; i < n; i++) {
      cin >> s;
      for (int j = 0; j < m; j++) {
        if (s[j] == '.') {
          c++;
          if (j < m - 1 && s[j + 1] == '.') {
            s[j + 1] = '*';
            c++;
            d++;
          }
          s[j] = '*';
        }
      }
    }
    int ans = 0;
    if (2 * x < y) {
      ans += c * x;
    } else {
      c -= 2 * d;
      ans += d * y + c * x;
    }
    cout << ans << endl;
  }
  return 0;
}
