static void performQueries ( String str , int q , int type [ ] , char ch [ ] , int freq [ ] ) {
  int n = str . length ( ) ;
  int [ ] [ ] L = new int [ MAX ] [ n ] ;
  int [ ] [ ] F = new int [ MAX ] [ n ] ;
  int [ ] cnt = new int [ MAX ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int k = str . charAt ( i ) - 'a' ;
    cnt [ k ] ++ ;
    for ( int j = 0 ;
    j < MAX ;
    j ++ ) {
      if ( k == j ) {
        L [ j ] [ cnt [ j ] ] = i ;
        F [ j ] [ cnt [ j ] ] = i ;
      }
      else L [ j ] [ cnt [ j ] ] = L [ j ] [ cnt [ j ] ] + 1 ;
    }
  }
  for ( int i = 0 ;
  i < q ;
  i ++ ) {
    if ( type [ i ] == 1 ) {
      System . out . print ( L [ ch [ i ] - 'a' ] [ freq [ i ] ] ) ;
    }
    else {
      System . out . print ( F [ ch [ i ] - 'a' ] [ freq [ i ] ] ) ;
    }
    System . out . print ( "\n" ) ;
  }
}

static void performQueries ( String str , int q , int type [ ] , char ch [ ] , int freq [ ] ) { int n = str . length ( ) ; int [ ] [ ] L = new int [ MAX ] [ n ] ; int [ ] [ ] F = new int [ MAX ] [ n ] ; int [ ] cnt = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { int k = str . charAt ( i ) - ' a ' ; cnt [ k ] ++ ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( k == j ) { L [ j ] [ cnt [ j ] ] = i ; F [ j ] [ cnt [ j ] ] = i ; } else L [ j ] [ cnt [ j ] ] = L [ j ] [ cnt [ j ] ] + 1 ; } } for ( int i = 0 ; i < q ; i ++ ) { if ( type [ i ] == 1 ) { System . out . print ( L [ ch [ i ] - ' a ' ] [ freq [ i ] ] ) ; } else { System . out . print ( F [ ch [ i ] - ' a ' ] [ freq [ i ] ] ) ; } System . out . print ( " \n " ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions))) body: (block (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions_expr (identifier))))) (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 (identifier)) dimensions: (dimensions_expr (identifier))))) (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 (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: (identifier)) 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: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (array_access array: (identifier) index: (identifier))) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (array_access array: (identifier) index: (identifier))) right: (identifier)))) alternative: (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (array_access array: (identifier) index: (identifier))) right: (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (array_access array: (identifier) index: (identifier))) right: (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 (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) index: (array_access array: (identifier) index: (identifier))))))) alternative: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) index: (array_access array: (identifier) index: (identifier)))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal))))))))