#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  for (int q = 0; q < t; q++) {
    int n, m, x, y, i, j;
    scanf("%d%d%d%d", &n, &m, &x, &y);
    char c;
    scanf("%c", &c);
    char arr[n][m];
    if (2 * x <= y) {
      int count = 0;
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          scanf("%c", &arr[i][j]);
          if (arr[i][j] == '.') count++;
        }
        scanf("%c", &c);
      }
      printf("%d", x * count);
    } else {
      int ans = 0;
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          scanf("%c", &arr[i][j]);
        }
        scanf("%c", &c);
      }
      if (m == 1) {
        int l = 0;
        for (i = 0; i < n; i++) {
          if (arr[i][0] == '.') l++;
        }
        printf("%d", l * x);
      } else {
        for (i = 0; i < n; i++) {
          for (j = 0; j < m - 1; j++) {
            if (arr[i][j] == '.' && arr[i][j + 1] == '.') {
              ans += y;
              arr[i][j] = 'd';
              arr[i][j + 1] = 'd';
            } else if (arr[i][j] == '.') {
              ans += x;
              arr[i][j] = 'd';
            }
          }
          if (arr[i][m - 1] == '.' && arr[i][m - 2] != '.') {
            ans += x;
            arr[i][m - 1] = 'd';
          }
        }
        printf("%d", ans);
      }
    }
    printf("\n");
  }
  return 0;
}
