public static void main ( String [ ] args ) {
  try {
    BufferedReader br = new BufferedReader ( new FileReader ( "A-large.in" ) ) ;
    int T = Integer . parseInt ( br . readLine ( ) ) ;
    PrintWriter pw = new PrintWriter ( new FileWriter ( "output" ) ) ;
    for ( int I = 1 ;
    I <= T ;
    I ++ ) {
      StringTokenizer st = new StringTokenizer ( br . readLine ( ) , " \n\t" , false ) ;
      int n = Integer . parseInt ( st . nextToken ( ) ) ;
      int Opos = 1 , Bpos = 1 ;
      int Oextra = 0 , Bextra = 0 ;
      int ret = 0 ;
      for ( int i = 0 ;
      i < n ;
      i ++ ) {
        int nextBot = ( st . nextToken ( ) . equals ( "O" ) ? 0 : 1 ) ;
        int button = Integer . parseInt ( st . nextToken ( ) ) ;
        if ( nextBot == 0 ) {
          int dist = Math . abs ( Opos - button ) ;
          if ( Oextra >= dist ) dist = 0 ;
          else dist -= Oextra ;
          ret += dist + 1 ;
          Bextra += dist + 1 ;
          Oextra = 0 ;
          Opos = button ;
        }
        else {
          int dist = Math . abs ( Bpos - button ) ;
          if ( Bextra >= dist ) dist = 0 ;
          else dist -= Bextra ;
          ret += dist + 1 ;
          Oextra += dist + 1 ;
          Bextra = 0 ;
          Bpos = button ;
        }
      }
      pw . println ( "Case #" + I + ": " + ret ) ;
    }
    br . close ( ) ;
    pw . flush ( ) ;
    pw . close ( ) ;
  }
  catch ( IOException ie ) {
    ie . printStackTrace ( ) ;
  }
}

public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new FileReader ( " A - large . in " ) ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( " output " ) ) ; for ( int I = 1 ; I <= T ; I ++ ) { StringTokenizer st = new StringTokenizer ( br . readLine ( ) , " ▁ \n \t " , false ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int Opos = 1 , Bpos = 1 ; int Oextra = 0 , Bextra = 0 ; int ret = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int nextBot = ( st . nextToken ( ) . equals ( " O " ) ? 0 : 1 ) ; int button = Integer . parseInt ( st . nextToken ( ) ) ; if ( nextBot == 0 ) { int dist = Math . abs ( Opos - button ) ; if ( Oextra >= dist ) dist = 0 ; else dist -= Oextra ; ret += dist + 1 ; Bextra += dist + 1 ; Oextra = 0 ; Opos = button ; } else { int dist = Math . abs ( Bpos - button ) ; if ( Bextra >= dist ) dist = 0 ; else dist -= Bextra ; ret += dist + 1 ; Oextra += dist + 1 ; Bextra = 0 ; Bpos = button ; } } pw . println ( " Case ▁ # " + I + " : ▁ " + ret ) ; } br . close ( ) ; pw . flush ( ) ; pw . close ( ) ; } catch ( IOException ie ) { ie . printStackTrace ( ) ; } }
(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 (try_statement 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: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (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))))))) (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: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) (string_literal) (false))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) 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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (parenthesized_expression (ternary_expression condition: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_literal))) consequence: (decimal_integer_literal) alternative: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) alternative: (expression_statement (assignment_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) alternative: (expression_statement (assignment_expression left: (identifier) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (catch_clause (catch_formal_parameter (catch_type (type_identifier)) name: (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))))