#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int arr[n][m];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        char c;
        cin >> c;
        if (c == '*')
          arr[i][j] = 0;
        else
          arr[i][j] = 1;
      }
    long int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (arr[i][j] == 1) {
          if (j + 1 < m && arr[i][j + 1] == 1) {
            ans += min(2 * x, y);
            j++;
          } else
            ans += x;
        }
      }
    }
    cout << ans << endl;
  }
}
