#include <bits/stdc++.h>
using namespace std;
char s[1005];
int main() {
  int t, n, m, i, j, k, x, y, c, s1;
  cin >> t;
  for (i = 1; i <= t; i++) {
    s1 = 0;
    cin >> n >> m >> x >> y;
    c = 1;
    if (y > 2 * x) c = 0;
    cin.get();
    for (j = 1; j <= n; j++) {
      cin.getline(s, 1005);
      s[m] = '*';
      if (s[0] == '.' && s[1] != '.') s1 += x;
      for (k = 1; k < m; k++)
        if (s[k] == '.' && s[k - 1] == '.') {
          if (c)
            s1 += y;
          else
            s1 += 2 * x;
          s[k] = s[k - 1] = '*';
        } else if (s[k] == '.' && s[k + 1] != '.') {
          s1 += x;
          s[k] = '*';
        }
    }
    cout << s1 << "\n";
  }
  return 0;
}
