#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m, x, y;
    cin >> n >> m >> x >> y;
    long long int ans = 0;
    char a[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      int count = 0;
      for (int j = 0; j < m; j++) {
        if (a[i][j] == '.') count++;
      }
      if (2 * x <= y)
        ans += x * count;
      else {
        long long int count1 = 0, count2 = 0;
        ;
        for (int j = 0; j < m; j++) {
          if (a[i][j] == '.' && j + 1 < m && a[i][j + 1] == '.') {
            count1++;
            j++;
          } else if (a[i][j] == '.')
            count2++;
        }
        ans += (count1 * y + count2 * x);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
