public static void main ( String [ ] args ) {
  Scanner scanner = new Scanner ( System . in ) ;
  int test = scanner . nextInt ( ) ;
  try ( BufferedWriter output = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) {
    outerLoop : while ( test -- > 0 ) {
      int n = scanner . nextInt ( ) ;
      boolean [ ] isReserved = new boolean [ n + 1 ] ;
      List < Integer > single = new ArrayList < > ( ) ;
      HashSet < Integer > singleP = new HashSet < > ( ) ;
      List < List < Integer >> priority = new ArrayList < > ( n + 1 ) ;
      priority . add ( new ArrayList < > ( ) ) ;
      for ( int i = 1 ;
      i <= n ;
      i ++ ) {
        singleP . add ( i ) ;
        int k = scanner . nextInt ( ) ;
        List < Integer > t = new ArrayList < > ( k ) ;
        for ( int j = 1 ;
        j <= k ;
        j ++ ) {
          int temp = scanner . nextInt ( ) ;
          t . add ( temp ) ;
        }
        priority . add ( t ) ;
      }
      for ( int i = 1 ;
      i <= n ;
      i ++ ) {
        boolean flag = false ;
        for ( int j : priority . get ( i ) ) {
          if ( ! isReserved [ j ] ) {
            isReserved [ j ] = true ;
            flag = true ;
            singleP . remove ( j ) ;
            break ;
          }
        }
        if ( ! flag ) {
          single . add ( i ) ;
        }
      }
      if ( single . size ( ) == 0 ) {
        output . write ( "OPTIMAL\n" ) ;
      }
      else {
        for ( int i : single ) {
          for ( int j : singleP ) {
            if ( ! priority . get ( i ) . contains ( j ) ) {
              output . write ( "IMPROVE\n" ) ;
              output . write ( i + " " + j + "\n" ) ;
              continue outerLoop ;
            }
          }
        }
        output . write ( "OPTIMAL\n" ) ;
      }
    }
    output . flush ( ) ;
  }
  catch ( IOException e ) {
  }
}

public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int test = scanner . nextInt ( ) ; try ( BufferedWriter output = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) { outerLoop : while ( test -- > 0 ) { int n = scanner . nextInt ( ) ; boolean [ ] isReserved = new boolean [ n + 1 ] ; List < Integer > single = new ArrayList < > ( ) ; HashSet < Integer > singleP = new HashSet < > ( ) ; List < List < Integer > > priority = new ArrayList < > ( n + 1 ) ; priority . add ( new ArrayList < > ( ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { singleP . add ( i ) ; int k = scanner . nextInt ( ) ; List < Integer > t = new ArrayList < > ( k ) ; for ( int j = 1 ; j <= k ; j ++ ) { int temp = scanner . nextInt ( ) ; t . add ( temp ) ; } priority . add ( t ) ; } for ( int i = 1 ; i <= n ; i ++ ) { boolean flag = false ; for ( int j : priority . get ( i ) ) { if ( ! isReserved [ j ] ) { isReserved [ j ] = true ; flag = true ; singleP . remove ( j ) ; break ; } } if ( ! flag ) { single . add ( i ) ; } } if ( single . size ( ) == 0 ) { output . write ( " OPTIMAL \n " ) ; } else { for ( int i : single ) { for ( int j : singleP ) { if ( ! priority . get ( i ) . contains ( j ) ) { output . write ( " IMPROVE \n " ) ; output . write ( i + " ▁ " + j + " \n " ) ; continue outerLoop ; } } } output . write ( " OPTIMAL \n " ) ; } } output . flush ( ) ; } catch ( IOException e ) { } }
(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)))) (try_with_resources_statement resources: (resource_specification (resource type: (type_identifier) name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))))) body: (block (labeled_statement (identifier) (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: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (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)) 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)) arguments: (argument_list)))) (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)) arguments: (argument_list (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) 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 (identifier)))) (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: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list (identifier))))) (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)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (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: (boolean_type) declarator: (variable_declarator name: (identifier) value: (false))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) body: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (break_statement))))) (if_statement condition: (parenthesized_expression (unary_expression operand: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) alternative: (block (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (string_literal)) right: (identifier)) right: (string_literal))))) (continue_statement (identifier)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block)))))