public static void main ( String [ ] args ) throws Exception {
  Scanner scan = new Scanner ( System . in ) ;
  int task = scan . nextInt ( ) ;
  int current = 1 ;
  while ( task -- > 0 ) {
    int N = scan . nextInt ( ) ;
    Level [ ] arr = new Level [ N ] ;
    int [ ] status = new int [ N ] ;
    int finished = 0 ;
    int star = 0 ;
    for ( int i = 0 ;
    i < N ;
    i ++ ) {
      arr [ i ] = new Level ( scan . nextInt ( ) , scan . nextInt ( ) ) ;
    }
    Arrays . sort ( arr ) ;
    int result = 0 ;
    while ( finished < N ) {
      for ( int i = 0 ;
      i < N ;
      i ++ ) {
        if ( status [ i ] == 2 ) {
          continue ;
        }
        if ( star >= arr [ i ] . high ) {
          star += 2 - status [ i ] ;
          status [ i ] = 2 ;
          finished ++ ;
          result ++ ;
        }
      }
      if ( finished == N ) {
        break ;
      }
      int select = - 1 ;
      int max = - 1 ;
      for ( int i = 0 ;
      i < N ;
      i ++ ) {
        if ( status [ i ] >= 1 ) {
          continue ;
        }
        if ( star >= arr [ i ] . low ) {
          if ( arr [ i ] . high > max ) {
            select = i ;
            max = arr [ i ] . high ;
          }
        }
      }
      if ( select == - 1 ) {
        result = - 1 ;
        break ;
      }
      else {
        result ++ ;
        status [ select ] = 1 ;
        star ++ ;
      }
    }
    System . out . println ( "Case #" + current + ": " + ( result == - 1 ? "Too Bad" : result ) ) ;
    current ++ ;
  }
}

public static void main ( String [ ] args ) throws Exception { Scanner scan = new Scanner ( System . in ) ; int task = scan . nextInt ( ) ; int current = 1 ; while ( task -- > 0 ) { int N = scan . nextInt ( ) ; Level [ ] arr = new Level [ N ] ; int [ ] status = new int [ N ] ; int finished = 0 ; int star = 0 ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = new Level ( scan . nextInt ( ) , scan . nextInt ( ) ) ; } Arrays . sort ( arr ) ; int result = 0 ; while ( finished < N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] == 2 ) { continue ; } if ( star >= arr [ i ] . high ) { star += 2 - status [ i ] ; status [ i ] = 2 ; finished ++ ; result ++ ; } } if ( finished == N ) { break ; } int select = - 1 ; int max = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] >= 1 ) { continue ; } if ( star >= arr [ i ] . low ) { if ( arr [ i ] . high > max ) { select = i ; max = arr [ i ] . high ; } } } if ( select == - 1 ) { result = - 1 ; break ; } else { result ++ ; status [ select ] = 1 ; star ++ ; } } System . out . println ( " Case ▁ # " + current + " : ▁ " + ( result == - 1 ? " Too ▁ Bad " : result ) ) ; current ++ ; } }
(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 (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)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (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))) (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) (method_invocation object: (identifier) 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))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (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: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (array_access array: (identifier) index: (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (break_statement))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (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: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) (break_statement)) alternative: (block (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) (expression_statement (update_expression (identifier))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (parenthesized_expression (ternary_expression condition: (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal))) consequence: (string_literal) alternative: (identifier))))))) (expression_statement (update_expression (identifier)))))))