#include <bits/stdc++.h>
using namespace std;
char a[100][1000] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m, x, y;
    cin >> n >> m >> x >> y;
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    long long int ans = 0;
    for (long long int i = 1; i <= n; i++) {
      for (long long int j = 1; j <= m; j++) {
        if (a[i][j] == '.') {
          long long int pos = j;
          for (long long int k = j; k <= m; k++) {
            if (a[i][k] == '.') {
              pos = k;
            } else {
              break;
            }
          }
          long long int temp = pos - j + 1;
          ans += min(temp * x, (temp / 2) * y + x * (temp % 2 == 1));
          j = pos;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
