#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int test;
  cin >> test;
  while (test--) {
    long long int n, m, x, y;
    cin >> n >> m >> x >> y;
    string s[n];
    for (long long int i = 0; i < n; i++) cin >> s[i];
    long long int ans = 0, c = 0;
    for (long long int i = 0; i < n; i++) {
      c = 0;
      for (long long int j = 0; j < m; j++) {
        if (s[i][j] == '.') {
          c++;
          if (j == m - 1 || s[i][j + 1] == '*') {
            long long int a = x * c;
            long long int b = y * (c / 2) + x * (c % 2);
            if (a > b)
              ans += b;
            else
              ans += a;
            c = 0;
          }
        }
      }
    }
    cout << ans << "\n";
  }
}
