#include <bits/stdc++.h>
using namespace std;
void __print(long long x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V>& x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T& x) {
  long long f{};
  cerr << '{';
  for (auto& i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long MOD{(long long)1e9 + 7};
const long long EPS{(long long)1e-9};
const long long N{(long long)1e5 + 5};
inline void fast_io(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  return;
}
inline void file_io(void) {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  return;
}
inline void solve_test() {
  long long n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<string> grid(n);
  for (long long i{0}; i < n; ++i) {
    cin >> grid[i];
  }
  long long cost{};
  for (long long i{0}; i < n; ++i) {
    for (long long j{0}; j < m; ++j) {
      if (grid[i][j] == '*') {
        continue;
      }
      if (j != m - 1 && grid[i][j + 1] == '.' && 2 * x > y) {
        cost += y;
        j++;
      } else {
        cost += x;
      }
    }
  }
  cout << cost << "\n";
  cost = 0;
  return;
}
signed main() {
  fast_io();
  long long t;
  cin >> t;
  while (t--) {
    solve_test();
  }
  return 0;
}
