#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, x, y;
    cin >> n >> m >> x >> y;
    long long flag = 0;
    if (2 * x < y) flag = 1;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      string s;
      cin >> s;
      long long pre = 0;
      for (long long j = 0; j < m; j++) {
        if (s[j] == '*') {
          if (flag) {
            ans += (j - pre) * x;
          } else {
            if (j - pre == 1)
              ans += (j - pre) * x;
            else if ((j - pre) % 2 == 0) {
              ans += ((j - pre) * y) / 2;
            } else {
              ans += ((j - pre) / 2) * y + x;
            }
          }
          pre = j + 1;
        }
      }
      long long yu = m - pre;
      if (yu == 1 || flag) {
        ans += yu * x;
      } else {
        if (yu % 2 == 0) {
          ans += (yu * y) / 2;
        } else {
          ans += (yu / 2) * y + x;
        }
      }
    }
    cout << ans << endl;
  }
}
