#include <bits/stdc++.h>
using namespace std;
long long t, n, m, x, y, cnt, ans;
char c;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n >> m >> x >> y;
    y = min(y, 2 * x);
    ans = 0;
    for (int i = 0; i < n; i++) {
      cnt = 0;
      for (int j = 0; j < m; j++) {
        cin >> c;
        if (c - '*')
          cnt++;
        else
          ans += (cnt % 2) * x + (cnt / 2) * y, cnt = 0;
      }
      ans += (cnt % 2) * x + (cnt / 2) * y;
    }
    cout << ans << endl;
  }
  return 0;
}
