#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, n, i, j, m, k, a, b, c = 0, tc = 1;
  cin >> t;
  while (t--) {
    cin >> n >> m >> a >> b;
    string s[n + 5];
    for (long long i = 0; i < n; i++) cin >> s[i];
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      c = 0;
      for (long long j = 0; j < s[i].size(); j++) {
        if (s[i][j] == '*') {
          if (b < 2 * a && c >= 2) {
            ans += (c / 2) * b;
            ans += (c % 2) * a;
          } else
            ans += c * a;
          c = 0;
        } else
          c++;
      }
      if (b < 2 * a && c >= 2) {
        ans += (c / 2) * b;
        ans += (c % 2) * a;
      } else
        ans += c * a;
    }
    cout << ans << endl;
  }
  return 0;
}
