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