public static void process ( ) throws IOException {
  int n = ni ( ) ;
  int m = ni ( ) ;
  HashMap < Integer , ArrayList < Integer >> map = new HashMap < Integer , ArrayList < Integer >> ( ) ;
  HashSet < Integer > set = new HashSet < Integer > ( ) ;
  for ( int i = 1 ;
  i <= n ;
  i ++ ) {
    ArrayList < Integer > list = new ArrayList < Integer > ( ) ;
    for ( int j = 1 ;
    j <= m ;
    j ++ ) {
      list . add ( ni ( ) ) ;
    }
    map . put ( list . get ( 0 ) , list ) ;
    set . add ( list . get ( 0 ) ) ;
  }
  ArrayList < ArrayList < Integer >> cols = new ArrayList < ArrayList < Integer >> ( ) ;
  for ( int i = 1 ;
  i <= m ;
  i ++ ) {
    ArrayList < Integer > list = new ArrayList < Integer > ( ) ;
    for ( int j = 1 ;
    j <= n ;
    j ++ ) {
      list . add ( ni ( ) ) ;
    }
    cols . add ( list ) ;
  }
  int i = 0 ;
  for ( i = 0 ;
  i < cols . size ( ) ;
  i ++ ) {
    if ( set . containsAll ( cols . get ( i ) ) ) {
      break ;
    }
  }
  for ( Integer x : cols . get ( i ) ) {
    ArrayList < Integer > list = map . get ( x ) ;
    for ( Integer z : list ) {
      p ( z + " " ) ;
    }
    pn ( "" ) ;
  }
}

public static void process ( ) throws IOException { int n = ni ( ) ; int m = ni ( ) ; HashMap < Integer , ArrayList < Integer > > map = new HashMap < Integer , ArrayList < Integer > > ( ) ; HashSet < Integer > set = new HashSet < Integer > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; for ( int j = 1 ; j <= m ; j ++ ) { list . add ( ni ( ) ) ; } map . put ( list . get ( 0 ) , list ) ; set . add ( list . get ( 0 ) ) ; } ArrayList < ArrayList < Integer > > cols = new ArrayList < ArrayList < Integer > > ( ) ; for ( int i = 1 ; i <= m ; i ++ ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; for ( int j = 1 ; j <= n ; j ++ ) { list . add ( ni ( ) ) ; } cols . add ( list ) ; } int i = 0 ; for ( i = 0 ; i < cols . size ( ) ; i ++ ) { if ( set . containsAll ( cols . get ( i ) ) ) { break ; } } for ( Integer x : cols . get ( i ) ) { ArrayList < Integer > list = map . get ( x ) ; for ( Integer z : list ) { p ( z + " ▁ " ) ; } pn ( " " ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier))))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier))))) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (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: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (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: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (type_identifier))))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (generic_type (type_identifier) (type_arguments (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: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (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: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (local_variable_declaration type: (integral_type) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) consequence: (block (break_statement))))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (identifier) body: (block (expression_statement (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (string_literal))))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (string_literal))))))))