#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int two = -1, one = -1;
    if (x < y) {
      one = x;
    } else {
      two = y;
    }
    int dot1 = 0, dot2 = 0, p = 0;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      dot1 = 0, dot2 = 0;
      for (int j = 0; j <= m;) {
        if (j < m - 1 && s[j] == '.' && s[j + 1] == '.') {
          dot2++;
          j += 2;
        } else if (s[j] == '.') {
          dot1++;
          j++;
        } else
          j++;
      }
      int sum1 = y * dot2 + dot1 * x;
      int sum2 = x * dot2 * 2 + dot1 * x;
      p += min(sum1, sum2);
    }
    cout << p << endl;
  }
}
