#include <bits/stdc++.h>
using namespace std;
char A[102][1005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int p;
    if (2 * x < y)
      p = 2 * x;
    else
      p = y;
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= m; k++) {
        cin >> A[j][k];
      }
    }
    long long int cost = 0;
    for (int j = 1; j <= n; j++) {
      int count = 0;
      for (int k = 1; k <= m; k++) {
        if (A[j][k] == '*') {
          int a = count / 2;
          if (count % 2 == 0)
            cost = cost + p * a;
          else
            cost = cost + p * a + x;
          count = 0;
        } else
          count++;
      }
      int b = count / 2;
      if (count % 2 == 0)
        cost = cost + p * b;
      else
        cost = cost + p * b + x;
    }
    cout << cost << endl;
  }
}
