#include <bits/stdc++.h>
int main(void) {
  int t;
  std::cin >> t;
  int rows[t];
  int columns[t];
  int single_cost[t];
  int double_cost[t];
  std::vector<std::vector<std::string>> pictures;
  for (int i = 0; i < t; i++) {
    std::cin >> rows[i] >> columns[i] >> single_cost[i] >> double_cost[i];
    std::vector<std::string> picture;
    std::string temp;
    std::cin >> std::ws;
    for (int j = 0; j < rows[i]; j++) {
      std::getline(std::cin, temp);
      picture.push_back(temp);
    }
    pictures.push_back(picture);
  }
  for (int i = 0; i < t; i++) {
    int cost = 0;
    std::vector<std::string> picture = pictures.at(i);
    double_cost[i] = std::min(2 * single_cost[i], double_cost[i]);
    for (int j = 0; j < rows[i]; j++) {
      for (int k = 0; k < columns[i]; k++) {
        if (picture.at(j).at(k) == '.') {
          if (k != (columns[i] - 1) && picture.at(j).at(k + 1) == '.') {
            cost = cost + double_cost[i];
            k = k + 1;
            continue;
          }
          cost = cost + single_cost[i];
          continue;
        }
      }
    }
    std::cout << cost << "\n";
  }
}
