public static void main ( String [ ] args ) throws Exception {
  Scanner s = new Scanner ( new File ( "B.in" ) ) ;
  PrintWriter out = new PrintWriter ( new File ( "B.out" ) ) ;
  int T = s . nextInt ( ) ;
  for ( int tc = 1 ;
  tc <= T ;
  tc ++ ) {
    out . print ( "Case #" + tc + ": " ) ;
    int N = s . nextInt ( ) ;
    Arrays . fill ( visit , 0 ) ;
    for ( int i = 0 ;
    i < N ;
    i ++ ) {
      a [ i ] = s . nextInt ( ) ;
      b [ i ] = s . nextInt ( ) ;
    }
    int ans = 0 ;
    int stars = 0 ;
    boolean progress = true ;
    outer : while ( progress ) {
      if ( stars == 2 * N ) break ;
      ans ++ ;
      progress = false ;
      for ( int i = 0 ;
      i < N ;
      i ++ ) {
        if ( visit [ i ] == 0 && b [ i ] <= stars ) {
          progress = true ;
          stars += 2 ;
          visit [ i ] = 2 ;
          continue outer ;
        }
      }
      for ( int i = 0 ;
      i < N ;
      i ++ ) {
        if ( visit [ i ] == 1 && b [ i ] <= stars ) {
          progress = true ;
          stars += 1 ;
          visit [ i ] = 2 ;
          continue outer ;
        }
      }
      int bestb = 0 ;
      int besti = 0 ;
      for ( int i = 0 ;
      i < N ;
      i ++ ) {
        if ( visit [ i ] == 0 && a [ i ] <= stars ) {
          progress = true ;
          if ( bestb < b [ i ] ) {
            bestb = b [ i ] ;
            besti = i ;
          }
        }
      }
      if ( progress ) {
        visit [ besti ] = 1 ;
        stars += 1 ;
      }
    }
    if ( stars == 2 * N ) out . println ( ans ) ;
    else out . println ( "Too Bad" ) ;
  }
  out . close ( ) ;
}

public static void main ( String [ ] args ) throws Exception { Scanner s = new Scanner ( new File ( " B . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " B . out " ) ) ; int T = s . nextInt ( ) ; for ( int tc = 1 ; tc <= T ; tc ++ ) { out . print ( " Case ▁ # " + tc + " : ▁ " ) ; int N = s . nextInt ( ) ; Arrays . fill ( visit , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = s . nextInt ( ) ; b [ i ] = s . nextInt ( ) ; } int ans = 0 ; int stars = 0 ; boolean progress = true ; outer : while ( progress ) { if ( stars == 2 * N ) break ; ans ++ ; progress = false ; for ( int i = 0 ; i < N ; i ++ ) { if ( visit [ i ] == 0 && b [ i ] <= stars ) { progress = true ; stars += 2 ; visit [ i ] = 2 ; continue outer ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( visit [ i ] == 1 && b [ i ] <= stars ) { progress = true ; stars += 1 ; visit [ i ] = 2 ; continue outer ; } } int bestb = 0 ; int besti = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( visit [ i ] == 0 && a [ i ] <= stars ) { progress = true ; if ( bestb < b [ i ] ) { bestb = b [ i ] ; besti = i ; } } } if ( progress ) { visit [ besti ] = 1 ; stars += 1 ; } } if ( stars == 2 * N ) out . println ( ans ) ; else out . println ( " Too ▁ Bad " ) ; } 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))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (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 (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal))))) (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) (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: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (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))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (labeled_statement (identifier) (while_statement condition: (parenthesized_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier)))) consequence: (break_statement)) (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (false))) (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 (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (continue_statement (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 (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (continue_statement (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 (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier)))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) alternative: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))