#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long t, n, m;
  long long k, i, x, y, ans1, ans2;
  bool flag;
  string s, s1, s2, s3, s4;
  cin >> t;
  while (t--) {
    cin >> n >> m >> x >> y;
    char a[n][m];
    for (long long i = 0; i < n; i++) {
      cin >> s;
      for (long long j = 0; j < m; j++) a[i][j] = s[j];
    }
    long long cost = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (a[i][j] == '.') {
          if (j < m - 1 && a[i][j + 1] == '.')
            cost += min(2 * x, y), j++;
          else
            cost += x;
        }
      }
    }
    cout << cost << endl;
  }
}
