#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
int g[1001][1001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    memset(g, 0, sizeof(g));
    int n, m, x, y;
    char s;
    cin >> n >> m >> x >> y;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        cin >> s;
        if (s == '*')
          g[i][j] = 0;
        else
          g[i][j] = 1;
      }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m;) {
        if (g[i][j] && g[i][j + 1]) {
          if (2 * x < y)
            ans += 2 * x;
          else
            ans += y;
          j += 2;
        } else if (g[i][j])
          ans += x, j++;
        else
          j++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
