#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    char a[n + 1][m + 1];
    long long counter = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        cin >> a[i][j];
        if (a[i][j] == '.') {
          counter++;
        }
      }
    }
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (a[i][j] == '.' && a[i][j + 1] == '.' && 2 * x > y) {
          sum += y;
          a[i][j] = '*';
          a[i][j + 1] = '*';
        }
        if (a[i][j] == '.') {
          sum += x;
          a[i][j] = '*';
        }
      }
    }
    cout << sum << endl;
  }
}
