#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m, sum = 0;
    double x, y;
    cin >> n >> m >> x >> y;
    char a[n][m];
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) cin >> a[i][j];
    }
    if (n == 1 && m == 1) {
      if (a[0][0] == '.')
        cout << x << "\n";
      else
        cout << 0 << "\n";
    } else if (m == 1) {
      for (long long int i = 0; i < n; i++) {
        for (long long int j = 0; j < m; j++) {
          if (a[i][j] == '.') sum = sum + x;
        }
      }
      cout << sum << "\n";
    } else {
      if (y / 2 < x) {
        for (long long int i = 0; i < n; i++) {
          for (long long int j = 0; j < m; j++) {
            if (a[i][j] == '.' && j != m - 1) {
              if (a[i][j + 1] == '.') {
                sum = sum + y;
                j++;
              } else
                sum = sum + x;
            } else {
              if (a[i][j] == '.') sum = sum + x;
            }
          }
        }
        cout << sum << "\n";
      } else {
        for (long long int i = 0; i < n; i++) {
          for (long long int j = 0; j < m; j++) {
            if (a[i][j] == '.') sum = sum + x;
          }
        }
        cout << sum << "\n";
      }
    }
  }
}
