#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline long long max3(long long a, long long b, long long c) {
  return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long min3(long long a, long long b, long long c) {
  return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));
}
void solve() {
  long long int n, m, t = 0, k = 0, x = 0, y = 0, z = 0, p, a1, a2, a3, a4, a5,
                      ex, che, var = 1, yd, f = 9223372036854775807, templ,
                      tempr;
  cin >> n >> m >> x >> y;
  char pic[n][m];
  for (long long int(i) = 0; (i) < (n); (i)++)
    for (long long int(j) = 0; (j) < (m); (j)++) {
      cin >> pic[i][j];
      if (pic[i][j] == '.') z++;
    }
  if (y >= 2 * x) {
    cout << z * x << "\n";
  } else {
    z = 0;
    for (long long int(i) = 0; (i) < (n); (i)++) {
      for (long long int(j) = 0; (j) < (m); (j)++) {
        if (pic[i][j] == '.') {
          if (j != m - 1 && pic[i][j + 1] == '.') {
            z += y;
            pic[i][j + 1] = '*';
          } else
            z += x;
        }
      }
    }
    cout << z << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T = 1, t = 0;
  cin >> T;
  while (t++ < T) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
