#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long t, m, n, k, x, y;
char a[1005][1005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> m >> n >> x >> y;
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= n; j++) cin >> a[i][j];
    long long ans = 0;
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= n; j++)
        if (a[i][j] == '.') {
          if (j < n && a[i][j + 1] == '.') {
            ans += min(2 * x, y);
            a[i][j + 1] = '*';
          } else
            ans += x;
          a[i][j] = '*';
        }
    cout << ans << '\n';
  }
}
