#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200105];
int xMove[] = {0, 1, 0, -1, 1, 1, -1, -1, 2, 2, -2, -2, 1, 1, -1, -1};
int yMove[] = {1, 0, -1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 2, -2, 2, -2};
int main() {
  cin.tie(0), cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  int TC = 1;
  int n, m, k, q;
  cin >> TC;
  for (int t = 1; t <= TC; t++) {
    int x, y;
    cin >> n >> m >> x >> y;
    string str[n];
    for (int i = 0; i < n; i++) cin >> str[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (j < m - 1) {
          if (str[i][j] == '.' and str[i][j + 1] == '.')
            ans += min(2 * x, y), j++;
          else if (str[i][j] == '.')
            ans += x;
        } else if (str[i][j] == '.')
          ans += x;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
