public static void main ( String [ ] args ) {
  Scanner ins = new Scanner ( System . in ) ;
  int cc ;
  int ntc = ins . nextInt ( ) ;
  for ( cc = 1 ;
  cc <= ntc ;
  cc ++ ) {
    int pos [ ] = {
      1 , 1 }, time [ ] = {
        0 , 0 };
        int cnt = ins . nextInt ( ) ;
        for ( int i = 0 ;
        i < cnt ;
        i ++ ) {
          String s = ins . next ( ) ;
          int r = 0 ;
          if ( s . equals ( "B" ) ) r = 1 ;
          int p = ins . nextInt ( ) ;
          int mtime = p - pos [ r ] ;
          if ( mtime < 0 ) mtime = - mtime ;
          mtime += time [ r ] + 1 ;
          if ( mtime <= time [ 1 - r ] ) mtime = time [ 1 - r ] + 1 ;
          time [ r ] = mtime ;
          pos [ r ] = p ;
        }
        int maxtime = time [ 0 ] ;
        if ( time [ 1 ] > maxtime ) maxtime = time [ 1 ] ;
        System . out . printf ( "Case #%d: %d\n" , cc , maxtime ) ;
      }
    }
    
public static void main ( String [ ] args ) { Scanner ins = new Scanner ( System . in ) ; int cc ; int ntc = ins . nextInt ( ) ; for ( cc = 1 ; cc <= ntc ; cc ++ ) { int pos [ ] = { 1 , 1 } , time [ ] = { 0 , 0 } ; int cnt = ins . nextInt ( ) ; for ( int i = 0 ; i < cnt ; i ++ ) { String s = ins . next ( ) ; int r = 0 ; if ( s . equals ( " B " ) ) r = 1 ; int p = ins . nextInt ( ) ; int mtime = p - pos [ r ] ; if ( mtime < 0 ) mtime = - mtime ; mtime += time [ r ] + 1 ; if ( mtime <= time [ 1 - r ] ) mtime = time [ 1 - r ] + 1 ; time [ r ] = mtime ; pos [ r ] = p ; } int maxtime = time [ 0 ] ; if ( time [ 1 ] > maxtime ) maxtime = time [ 1 ] ; System . out . printf ( " Case ▁ # % d : ▁ % d \n " , cc , maxtime ) ; } }
(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))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (for_statement init: (assignment_expression left: (identifier) right: (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) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_literal))) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_initializer (decimal_integer_literal) (decimal_integer_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 (local_variable_declaration type: (type_identifier) 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))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (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: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (decimal_integer_literal) right: (identifier))))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (decimal_integer_literal))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal) (identifier) (identifier))))))))