#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int ans = 0;
    y = min(y, 2 * x);
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < m; j++) {
        if (s[j] == '*')
          continue;
        else {
          int k = j;
          while (k + 1 < m && s[k + 1] == '.') {
            k += 1;
          }
          int l = k + 1 - j;
          ans += ((l % 2) * x) + ((l / 2) * y);
          j = k + 1;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
