public static void main ( String args [ ] ) throws Exception {
  in = new BufferedReader ( new InputStreamReader ( new FileInputStream ( "b.in" ) ) ) ;
  out = new PrintWriter ( new OutputStreamWriter ( new FileOutputStream ( "b.out" ) ) ) ;
  int T = nextInt ( ) ;
  for ( int t = 0 ;
  t < T ;
  t ++ ) {
    String n = "0" + next ( ) ;
    int cnts [ ] = new int [ 10 ] ;
    String ans ;
    PLoop : for ( int p = n . length ( ) - 1 ;
    ;
    p -- ) {
      int c = n . charAt ( p ) - '0' ;
      ++ cnts [ c ] ;
      for ( int nc = c + 1 ;
      nc < 10 ;
      ++ nc ) {
        if ( cnts [ nc ] > 0 ) {
          StringBuilder sb = new StringBuilder ( ) ;
          sb . append ( n . substring ( 0 , p ) ) ;
          sb . append ( ( char ) ( '0' + nc ) ) ;
          -- cnts [ nc ] ;
          for ( int i = 0 ;
          i < 10 ;
          ++ i ) {
            while ( cnts [ i ] > 0 ) {
              sb . append ( ( char ) ( '0' + i ) ) ;
              -- cnts [ i ] ;
            }
          }
          ans = sb . toString ( ) ;
          break PLoop ;
        }
      }
      if ( p == 0 ) {
        throw new AssertionError ( ) ;
      }
    }
    out . println ( "Case #" + ( t + 1 ) + ": " + new BigInteger ( ans ) . toString ( ) ) ;
  }
  in . close ( ) ;
  out . close ( ) ;
}

public static void main ( String args [ ] ) throws Exception { in = new BufferedReader ( new InputStreamReader ( new FileInputStream ( " b . in " ) ) ) ; out = new PrintWriter ( new OutputStreamWriter ( new FileOutputStream ( " b . out " ) ) ) ; int T = nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { String n = "0" + next ( ) ; int cnts [ ] = new int [ 10 ] ; String ans ; PLoop : for ( int p = n . length ( ) - 1 ; ; p -- ) { int c = n . charAt ( p ) - '0' ; ++ cnts [ c ] ; for ( int nc = c + 1 ; nc < 10 ; ++ nc ) { if ( cnts [ nc ] > 0 ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( n . substring ( 0 , p ) ) ; sb . append ( ( char ) ( '0' + nc ) ) ; -- cnts [ nc ] ; for ( int i = 0 ; i < 10 ; ++ i ) { while ( cnts [ i ] > 0 ) { sb . append ( ( char ) ( '0' + i ) ) ; -- cnts [ i ] ; } } ans = sb . toString ( ) ; break PLoop ; } } if ( p == 0 ) { throw new AssertionError ( ) ; } } out . println ( " Case ▁ # " + ( t + 1 ) + " : ▁ " + new BigInteger ( ans ) . toString ( ) ) ; } in . close ( ) ; out . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) (throws (type_identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (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 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: (binary_expression left: (string_literal) right: (method_invocation name: (identifier) arguments: (argument_list))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier))) (labeled_statement (identifier) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)))) (expression_statement (update_expression (array_access array: (identifier) index: (identifier)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) 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 (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (cast_expression type: (integral_type) value: (parenthesized_expression (binary_expression left: (character_literal) right: (identifier))))))) (expression_statement (update_expression (array_access array: (identifier) index: (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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (while_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (cast_expression type: (integral_type) value: (parenthesized_expression (binary_expression left: (character_literal) right: (identifier))))))) (expression_statement (update_expression (array_access array: (identifier) index: (identifier)))))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (break_statement (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (throw_statement (object_creation_expression type: (type_identifier) arguments: (argument_list)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (string_literal)) right: (method_invocation object: (object_creation_expression type: (type_identifier) arguments: (argument_list (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)))))