public static void main ( String [ ] args ) {
  InputStream inputStream = System . in ;
  OutputStream outputStream = System . out ;
  InputReader in = new InputReader ( inputStream ) ;
  PrintWriter out = new PrintWriter ( outputStream ) ;
  int t = in . nextInt ( ) ;
  while ( t -- > 0 ) {
    int n = in . nextInt ( ) ;
    int m = in . nextInt ( ) ;
    int x = in . nextInt ( ) ;
    int y = in . nextInt ( ) ;
    char [ ] [ ] arr = new char [ n ] [ m ] ;
    int horizontal_pair = 0 ;
    int single_dots = 0 ;
    for ( int i = 0 ;
    i < n ;
    i ++ ) {
      String st = in . next ( ) ;
      String temp = st ;
      horizontal_pair += ( m - temp . replace ( ".." , "" ) . length ( ) ) / 2 ;
      for ( int j = 0 ;
      j < m ;
      j ++ ) {
        arr [ i ] [ j ] = st . charAt ( j ) ;
        if ( arr [ i ] [ j ] == '.' ) single_dots ++ ;
      }
    }
    int val1 = single_dots * x ;
    int val2 = horizontal_pair * y + ( single_dots - horizontal_pair * 2 ) * x ;
    out . println ( Math . min ( val1 , val2 ) ) ;
  }
  out . close ( ) ;
}

public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; int t = in . nextInt ( ) ; while ( t -- > 0 ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int x = in . nextInt ( ) ; int y = in . nextInt ( ) ; char [ ] [ ] arr = new char [ n ] [ m ] ; int horizontal_pair = 0 ; int single_dots = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String st = in . next ( ) ; String temp = st ; horizontal_pair += ( m - temp . replace ( " . . " , " " ) . length ( ) ) / 2 ; for ( int j = 0 ; j < m ; j ++ ) { arr [ i ] [ j ] = st . charAt ( j ) ; if ( arr [ i ] [ j ] == ' . ' ) single_dots ++ ; } } int val1 = single_dots * x ; int val2 = horizontal_pair * y + ( single_dots - horizontal_pair * 2 ) * x ; out . println ( Math . min ( val1 , val2 ) ) ; } out . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (string_literal))) name: (identifier) arguments: (argument_list)))) right: (decimal_integer_literal)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (character_literal))) consequence: (expression_statement (update_expression (identifier)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))