#include <bits/stdc++.h>
using namespace std;
const int mxN = 200000;
int solve(string s, int single_tile_cost, int double_tile_cost) {
  int answer = 0;
  int ctr = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '.') {
      ctr++;
    } else {
      if (ctr % 2) {
        answer += (ctr / 2) * double_tile_cost + single_tile_cost;
      } else {
        answer += (ctr / 2) * double_tile_cost;
      }
      ctr = 0;
    }
  }
  if (s[(int)s.size() - 1] == '.') {
    if (ctr % 2) {
      answer += (ctr / 2) * double_tile_cost + single_tile_cost;
    } else {
      answer += (ctr / 2) * double_tile_cost;
    }
  }
  return answer;
}
int solve(string s, int single_tile_cost) {
  int cou = count(s.begin(), s.end(), '.');
  return single_tile_cost * cou;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int answer = 0;
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    bool use_one_cross_one_always = ((2 * x) <= y) ? true : false;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (use_one_cross_one_always) {
        answer += solve(s, x);
      } else {
        answer += solve(s, x, y);
      }
    }
    cout << answer << "\n";
  }
  return 0;
}
