#include <bits/stdc++.h>
using namespace std;
int findMin(vector<vector<char>> &squares, int x, int y) {
  int n = squares.size();
  int m = squares[0].size();
  int minCost = min((2 * x), y);
  int ans = 0;
  for (int i = 0; i < squares.size(); i++) {
    for (int j = 0; j < squares[i].size();) {
      if (squares[i][j] == '.') {
        if (j + 1 < squares[i].size() && squares[i][j + 1] == '.') {
          ans = ans + minCost;
          j = j + 2;
        } else {
          ans = ans + x;
          j = j + 1;
        }
      } else {
        j = j + 1;
      }
    }
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<vector<char>> squares;
    for (int i = 0; i < n; i++) {
      vector<char> row(m);
      for (int j = 0; j < m; j++) {
        cin >> row[j];
      }
      squares.push_back(row);
    }
    cout << findMin(squares, x, y) << endl;
  }
}
