#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200010;
const long long INF = LLONG_MAX / 4;
long long A[110][1010];
void solve() {
  long long n, m, cost1, cost2;
  cin >> n >> m >> cost1 >> cost2;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      char x;
      cin >> x;
      if (x == '.')
        A[i][j] = 0;
      else
        A[i][j] = 1;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (A[i][j] == 1) continue;
      if (!A[i][j] and j < m - 1 and !A[i][j + 1] and cost2 < cost1 * 2) {
        A[i][j] = A[i][j + 1] = 1;
        ans += cost2;
      } else {
        A[i][j] = 1;
        ans += cost1;
      }
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) solve();
}
