#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
char G[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int T;
  cin >> T;
  for (int tc = 1; tc <= T; tc++) {
    long long int n, m, x, y;
    cin >> n >> m >> x >> y;
    long long int w = 0, b = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> G[i][j];
        if (G[i][j] == '*')
          b++;
        else
          w++;
      }
    }
    long long int ans = w * x;
    long long int cur = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        if (j + 1 <= m && G[i][j] == '.' && G[i][j + 1] == '.') {
          cur += min(x + x, y);
          G[i][j] = 'x';
          G[i][j + 1] = 'x';
        }
        if (G[i][j] == '.') {
          cur += x;
          G[i][j] = 'x';
        }
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        if (G[i][j] == '.') {
          cur += x;
          G[i][j] = 'x';
        }
      }
    ans = min(ans, cur);
    cout << ans << "\n";
  }
}
