#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    long long ans = 0;
    string s;
    bool ok;
    if (a * 2 <= b)
      ok = true;
    else
      ok = false;
    for (int i = 0; i < n; ++i) {
      cin >> s;
      bool done = true;
      for (int j = 0; j < m; ++j) {
        if (s[j] == '*') {
          if (!done) ans += a * 1LL;
          done = true;
        } else {
          if (!done) {
            if (ok)
              ans += a * 2LL;
            else
              ans += b * 1LL;
            done = true;
          } else
            done = false;
        }
      }
      if (!done) ans += a * 1LL;
    }
    cout << ans << endl;
  }
  return 0;
}
