public static void main ( String [ ] args ) {
  FastReader scan = new FastReader ( ) ;
  PrintWriter out = new PrintWriter ( System . out ) ;
  int n = scan . nextInt ( ) , q = scan . nextInt ( ) ;
  int [ ] p = new int [ n + 1 ] ;
  char prev = 'z' ;
  char [ ] a = scan . next ( ) . toCharArray ( ) ;
  for ( int i = 1 ;
  i <= n ;
  i ++ ) {
    if ( a [ i - 1 ] == 'C' && prev == 'A' ) p [ i ] ++ ;
    p [ i ] += p [ i - 1 ] ;
    prev = a [ i - 1 ] ;
  }
  for ( int i = 0 ;
  i < q ;
  i ++ ) {
    int l = scan . nextInt ( ) - 1 , r = scan . nextInt ( ) ;
    int get = p [ r ] - p [ l ] ;
    if ( l > 0 && a [ l ] == 'C' && a [ l - 1 ] == 'A' ) get -- ;
    out . println ( get ) ;
  }
  out . close ( ) ;
}

public static void main ( String [ ] args ) { FastReader scan = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = scan . nextInt ( ) , q = scan . nextInt ( ) ; int [ ] p = new int [ n + 1 ] ; char prev = ' z ' ; char [ ] a = scan . next ( ) . toCharArray ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( a [ i - 1 ] == ' C ' && prev == ' A ' ) p [ i ] ++ ; p [ i ] += p [ i - 1 ] ; prev = a [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) { int l = scan . nextInt ( ) - 1 , r = scan . nextInt ( ) ; int get = p [ r ] - p [ l ] ; if ( l > 0 && a [ l ] == ' C ' && a [ l - 1 ] == ' A ' ) get -- ; out . println ( get ) ; } out . close ( ) ; }
(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 (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_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 (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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 (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (character_literal))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) 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 (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (character_literal)) right: (binary_expression left: (identifier) right: (character_literal)))) consequence: (expression_statement (update_expression (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: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (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 (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))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal))) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (character_literal)))) consequence: (expression_statement (update_expression (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))