#include <bits/stdc++.h>
using namespace std;
char s[1005];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m, x, y;
    scanf("%d %d %d %d", &n, &m, &x, &y);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      scanf("%s", s);
      int cnt = 0;
      for (int j = 0; j < m; ++j) {
        if (s[j] == '.')
          ++cnt;
        else
          cnt = 0;
        if (j == m - 1 || s[j + 1] == '*') {
          ans += min(x * 2, y) * (cnt / 2) + (cnt & 1) * x;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
