#include <bits/stdc++.h>
using namespace std;
void dfs(int s, vector<int> adj[], vector<bool> vis) {
  vis[s] = true;
  for (auto i = adj[s].begin(); i != adj[s].end(); i++) {
    if (!vis[*i]) {
      dfs(*i, adj, vis);
    }
  }
}
long long power(long long x, long long n) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = result * x;
    x = x * x;
    n = n / 2;
  }
  return result;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    char a[n][m];
    long long dots = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        if (a[i][j] == '.') {
          dots++;
        }
      }
    }
    if (m == 1) {
      cout << x * dots << endl;
      continue;
    }
    long long sum = 0;
    if (2 * x <= y) {
      cout << x * dots << endl;
    } else {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] == '*') {
            continue;
          }
          long long k = j;
          long long c = 0;
          while (k < m && a[i][k] == '.') {
            c++;
            k++;
          }
          j = k;
          sum += y * (c / 2);
          sum += x * (c % 2);
        }
      }
      cout << sum << endl;
    }
  }
  return 0;
}
