public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int cases = sc . nextInt ( ) ;
  for ( int caze = 1 ;
  caze <= cases ;
  caze ++ ) {
    int P = sc . nextInt ( ) ;
    long [ ] vals = new long [ P ] , freqs = new long [ P ] ;
    Map < Long , Integer > pos = new HashMap < Long , Integer > ( ) ;
    for ( int i = 0 ;
    i < vals . length ;
    i ++ ) {
      vals [ i ] = sc . nextLong ( ) ;
      pos . put ( vals [ i ] , i ) ;
    }
    long total = 0 ;
    for ( int i = 0 ;
    i < vals . length ;
    i ++ ) {
      freqs [ i ] = sc . nextLong ( ) ;
      total += freqs [ i ] ;
    }
    int cant = 0 ;
    long tmp = total ;
    while ( tmp > 1 ) {
      tmp /= 2 ;
      cant ++ ;
    }
    long [ ] ans = new long [ cant ] ;
    int sumIdx = 0 , setIdx = 0 ;
    for ( setIdx = 0 ;
    setIdx < cant ;
    setIdx ++ ) {
      for ( int m = 0 ;
      m < ( 1 << setIdx ) ;
      m ++ ) {
        if ( setIdx != 0 && ( m & ( 1 << ( setIdx - 1 ) ) ) == 0 ) continue ;
        long val = 0 ;
        for ( int i = 0 ;
        i < setIdx ;
        i ++ ) if ( ( m & ( 1 << i ) ) != 0 ) val += ans [ i ] ;
        freqs [ pos . get ( val ) ] -- ;
      }
      while ( freqs [ sumIdx ] == 0 ) {
        sumIdx ++ ;
      }
      ans [ setIdx ] = vals [ sumIdx ] ;
    }
    System . out . print ( "Case #" + caze + ":" ) ;
    for ( int i = 0 ;
    i < ans . length ;
    i ++ ) {
      System . out . print ( " " + ans [ i ] ) ;
    }
    System . out . println ( ) ;
  }
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int P = sc . nextInt ( ) ; long [ ] vals = new long [ P ] , freqs = new long [ P ] ; Map < Long , Integer > pos = new HashMap < Long , Integer > ( ) ; for ( int i = 0 ; i < vals . length ; i ++ ) { vals [ i ] = sc . nextLong ( ) ; pos . put ( vals [ i ] , i ) ; } long total = 0 ; for ( int i = 0 ; i < vals . length ; i ++ ) { freqs [ i ] = sc . nextLong ( ) ; total += freqs [ i ] ; } int cant = 0 ; long tmp = total ; while ( tmp > 1 ) { tmp /= 2 ; cant ++ ; } long [ ] ans = new long [ cant ] ; int sumIdx = 0 , setIdx = 0 ; for ( setIdx = 0 ; setIdx < cant ; setIdx ++ ) { for ( int m = 0 ; m < ( 1 << setIdx ) ; m ++ ) { if ( setIdx != 0 && ( m & ( 1 << ( setIdx - 1 ) ) ) == 0 ) continue ; long val = 0 ; for ( int i = 0 ; i < setIdx ; i ++ ) if ( ( m & ( 1 << i ) ) != 0 ) val += ans [ i ] ; freqs [ pos . get ( val ) ] -- ; } while ( freqs [ sumIdx ] == 0 ) { sumIdx ++ ; } ans [ setIdx ] = vals [ sumIdx ] ; } System . out . print ( " Case ▁ # " + caze + " : " ) ; for ( int i = 0 ; i < ans . length ; i ++ ) { System . out . print ( " ▁ " + ans [ i ] ) ; } System . out . println ( ) ; } }
(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: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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: (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)))) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) arguments: (argument_list)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (identifier)))))) (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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (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: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (update_expression (identifier))))) (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))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier)))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))))) right: (decimal_integer_literal)))) consequence: (continue_statement)) (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: (if_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))))) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))))) (expression_statement (update_expression (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (while_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) body: (block (expression_statement (update_expression (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (string_literal) right: (array_access array: (identifier) index: (identifier)))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list)))))))