public static void main ( String [ ] args ) throws Exception {
  BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  PrintWriter pw = new PrintWriter ( "A.txt" ) ;
  int T = Integer . parseInt ( in . readLine ( ) ) ;
  for ( int c = 1 ;
  c <= T ;
  c ++ ) {
    String s = in . readLine ( ) ;
    int [ ] fl = new int [ s . length ( ) ] ;
    int nfl = 0 ;
    while ( nfl < s . length ( ) ) {
      char last = ( char ) ( 'A' - 1 ) ;
      int firstL = - 1 ;
      for ( int i = 0 ;
      i < s . length ( ) ;
      i ++ ) {
        if ( fl [ i ] == 0 && s . charAt ( i ) > last ) {
          last = s . charAt ( i ) ;
          firstL = i ;
        }
      }
      for ( int i = firstL ;
      i < s . length ( ) ;
      i ++ ) {
        if ( fl [ i ] == 0 ) {
          nfl ++ ;
          if ( s . charAt ( i ) == last ) {
            fl [ i ] = 1 ;
          }
          else fl [ i ] = - 1 ;
        }
      }
    }
    String ans = "" ;
    for ( int i = 0 ;
    i < s . length ( ) ;
    i ++ ) {
      if ( fl [ i ] == 1 ) {
        ans = s . charAt ( i ) + ans ;
      }
      else if ( fl [ i ] == - 1 ) {
        ans = ans + s . charAt ( i ) ;
      }
    }
    pw . println ( "Case #" + c + ": " + ans ) ;
  }
  pw . close ( ) ;
}

public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( " A . txt " ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int c = 1 ; c <= T ; c ++ ) { String s = in . readLine ( ) ; int [ ] fl = new int [ s . length ( ) ] ; int nfl = 0 ; while ( nfl < s . length ( ) ) { char last = ( char ) ( ' A ' - 1 ) ; int firstL = - 1 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 0 && s . charAt ( i ) > last ) { last = s . charAt ( i ) ; firstL = i ; } } for ( int i = firstL ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 0 ) { nfl ++ ; if ( s . charAt ( i ) == last ) { fl [ i ] = 1 ; } else fl [ i ] = - 1 ; } } } String ans = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 1 ) { ans = s . charAt ( i ) + ans ; } else if ( fl [ i ] == - 1 ) { ans = ans + s . charAt ( i ) ; } } pw . println ( " Case ▁ # " + c + " : ▁ " + ans ) ; } pw . 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 (field_access object: (identifier) field: (identifier)))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (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)))))) (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (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: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (cast_expression type: (integral_type) value: (parenthesized_expression (binary_expression left: (character_literal) right: (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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 (expression_statement (update_expression (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))) alternative: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal))))))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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 (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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)))))