public static void main ( String [ ] args ) throws Exception {
  BufferedReader input = new BufferedReader ( new FileReader ( FILE_NAME + ".in" ) ) ;
  BufferedWriter output = new BufferedWriter ( new FileWriter ( FILE_NAME + ".out" ) ) ;
  final int T = Integer . parseInt ( input . readLine ( ) ) ;
  for ( int t = 0 ;
  t < T ;
  t ++ ) {
    output . append ( "Case #" + ( t + 1 ) + ": " ) ;
    char [ ] chars = input . readLine ( ) . trim ( ) . toCharArray ( ) ;
    int k = chars . length - 1 ;
    while ( k > 0 && chars [ k ] <= chars [ k - 1 ] ) k -- ;
    if ( k > 0 ) {
      int p = k ;
      char min = '9' + 1 ;
      for ( int q = k ;
      q < chars . length ;
      q ++ ) {
        if ( chars [ q ] > chars [ k - 1 ] && chars [ q ] < min ) {
          min = chars [ q ] ;
          p = q ;
        }
      }
      char c = chars [ p ] ;
      chars [ p ] = chars [ k - 1 ] ;
      chars [ k - 1 ] = c ;
      Arrays . sort ( chars , k , chars . length ) ;
      for ( int x = 0 ;
      x < chars . length ;
      x ++ ) output . append ( chars [ x ] ) ;
    }
    else {
      Arrays . sort ( chars ) ;
      int j = 0 ;
      while ( chars [ j ] == '0' ) j ++ ;
      output . append ( chars [ j ] ) ;
      for ( int x = 0 ;
      x < j + 1 ;
      x ++ ) output . append ( '0' ) ;
      for ( int x = j + 1 ;
      x < chars . length ;
      x ++ ) output . append ( chars [ x ] ) ;
    }
    output . append ( '\n' ) ;
  }
  output . close ( ) ;
}

public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new FileReader ( FILE_NAME + " . in " ) ) ; BufferedWriter output = new BufferedWriter ( new FileWriter ( FILE_NAME + " . out " ) ) ; final int T = Integer . parseInt ( input . readLine ( ) ) ; for ( int t = 0 ; t < T ; t ++ ) { output . append ( " Case ▁ # " + ( t + 1 ) + " : ▁ " ) ; char [ ] chars = input . readLine ( ) . trim ( ) . toCharArray ( ) ; int k = chars . length - 1 ; while ( k > 0 && chars [ k ] <= chars [ k - 1 ] ) k -- ; if ( k > 0 ) { int p = k ; char min = '9' + 1 ; for ( int q = k ; q < chars . length ; q ++ ) { if ( chars [ q ] > chars [ k - 1 ] && chars [ q ] < min ) { min = chars [ q ] ; p = q ; } } char c = chars [ p ] ; chars [ p ] = chars [ k - 1 ] ; chars [ k - 1 ] = c ; Arrays . sort ( chars , k , chars . length ) ; for ( int x = 0 ; x < chars . length ; x ++ ) output . append ( chars [ x ] ) ; } else { Arrays . sort ( chars ) ; int j = 0 ; while ( chars [ j ] == '0' ) j ++ ; output . append ( chars [ j ] ) ; for ( int x = 0 ; x < j + 1 ; x ++ ) output . append ( '0' ) ; for ( int x = j + 1 ; x < chars . length ; x ++ ) output . append ( chars [ x ] ) ; } output . append ( ' \n ' ) ; } output . 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 (binary_expression left: (identifier) right: (string_literal)))))))) (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 (binary_expression left: (identifier) right: (string_literal)))))))) (local_variable_declaration (modifiers) 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 (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (string_literal) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (string_literal))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) body: (expression_statement (update_expression (identifier)))) (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: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (character_literal) right: (decimal_integer_literal)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier) (field_access object: (identifier) field: (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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier))))))) alternative: (block (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: (array_access array: (identifier) index: (identifier)) right: (character_literal))) body: (expression_statement (update_expression (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (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: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal))))) (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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (character_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))