#include <bits/stdc++.h>
using namespace std;
bool check(long long int arr1[], long long int arr2[], long long int m,
           long long int n) {
  sort(arr1, arr1 + n);
  sort(arr2, arr2 + m);
  for (int i = 0; i < n; i++)
    if (arr1[i] != arr2[i]) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m, x, y;
    cin >> n >> m >> x >> y;
    char a[n][m], dp[n + 1][m + 1];
    long long int c = 0, ans = 0;
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    memset(dp, 0, sizeof(dp));
    dp[1][1] = x;
    for (long long int i = 0; i < n; i++) {
      c = 0;
      for (long long int j = 0; j < m; j++) {
        if (a[i][j] == '.' && j + 1 < m && a[i][j + 1] == '.') {
          ans += min(x * 2, y);
          j++;
        } else if (a[i][j] == '.')
          ans += x;
      }
    }
    cout << ans << "\n";
  }
}
