#include <bits/stdc++.h>
using namespace std;
template <typename T>
void deb(T v[], long long n) {
  if (false) cerr << "ARRAY   : ";
  long long i;
  for (i = 0; i < n; i++)
    if (false) cerr << v[i] << " ";
  if (false) cerr << endl;
}
template <typename T>
void deb(set<T> s) {
  if (false) cerr << "SET     : ";
  for (auto it : s)
    if (false) cerr << it << " ";
  if (false) cerr << endl;
}
template <typename T>
void deb(vector<T> v) {
  if (false) cerr << "VECTOR : ";
  long long i;
  for (i = 0; i < v.size(); i++)
    if (false) cerr << v[i] << " ";
  if (false) cerr << endl;
}
template <typename T>
void deb(stack<T> s) {
  if (false) cerr << "STACK   : ";
  stack<T> st = s;
  while (st.size()) {
    if (false) cerr << st.top() << " ";
    st.pop();
  };
  if (false) cerr << endl;
}
template <typename T>
void deb(queue<T> q) {
  if (false) cerr << "Queue   : ";
  queue<T> qq = q;
  while (qq.size()) {
    if (false) cerr << qq.front() << " ";
    qq.pop();
  };
  if (false) cerr << endl;
}
void deb(map<long long, long long> m) {
  if (false) cerr << "MAP : ";
  for (auto it : m)
    if (false) cerr << it.first << " : " << it.second << endl;
}
void deb(unordered_map<long long, long long> m) {
  if (false) cerr << "MAP : ";
  for (auto it : m)
    if (false) cerr << it.first << " : " << it.second << endl;
}
template <typename T>
T abs(T a) {
  return a < 0 ? a * -1 : a;
}
void swap(long long &x, long long &y);
bool isPrime(long long n);
long long nCrModp(long long n, long long r, long long p);
long long power(long long x, long long y, long long p);
long long gcdExtended(long long a, long long b, long long *x, long long *y);
long long modInverse(long long b, long long m);
long long modDivide(long long a, long long b, long long m);
void simpleSieve(long long N, bool[]);
void PrimeDivisorSieve(long long N, long long prime[]);
long long testCases;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> testCases;
  while (testCases--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    string arr[n];
    long long i, j, k;
    for (i = 0; i < n; i++) cin >> arr[i];
    long long ct = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (arr[i][j] == '.') ct++;
      }
    }
    if (x * 2 > y) {
      long long ans = 0;
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          long long len = 0;
          while (arr[i][j] == '.') {
            len++;
            j++;
          }
          if (len == 0) {
          } else if (len % 2 == 1) {
            ans += y * (len / 2);
            ans += x;
          } else {
            ans += y * (len / 2);
          }
        }
      }
      cout << ans << endl;
    } else {
      cout << ct * x << endl;
    }
  }
  return 0;
}
void simpleSieve(long long N, bool prime[]) {
  long long i, j;
  for (i = 0; i < N + 1; i++) prime[i] = true;
  for (i = 2; i * i <= N; i++) {
    if (prime[i]) {
      for (j = i * i; j <= N; j++) {
        prime[j] = false;
      }
    }
  }
}
void PrimeDivisorSieve(long long N, long long prime[]) {
  long long i, j;
  for (i = 0; i < N + 1; i++) prime[i] = i;
  for (i = 2; i * i <= N; i++) {
    if (prime[i] == i) {
      for (j = i; j <= N; j++) {
        if (prime[j] == j) prime[j] = i;
      }
    }
  }
}
void swap(long long &x, long long &y) {
  x ^= y;
  y ^= x;
  x ^= y;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i < n; i++)
    if (n % i == 0) return false;
  return true;
}
long long nCrModp(long long n, long long r, long long p) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p;
  }
  return C[r];
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long b, long long m) {
  long long x, y;
  long long g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
long long modDivide(long long a, long long b, long long m) {
  a = a % m;
  long long inv = modInverse(b, m);
  if (inv == -1)
    return -1;
  else
    return (inv * a) % m;
}
