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