#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<string> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long ans = 0;
    long long flag = 0;
    if (y < 2 * x) flag = 1;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (a[i][j] == '*') continue;
        if (j == m - 1)
          ans += x;
        else {
          if (a[i][j + 1] == '.' && flag) {
            ans += y;
            a[i][j + 1] = '*';
          } else
            ans += x;
        }
      }
    }
    cout << ans << endl;
  }
}
