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