import numpy as np

N,Q = list(map(int,input().split()))

S = np.array(list('_' + eval(input())), dtype='U2')

A = (S == 'A')

C = (S == 'C')

AC = (A[:-1] & C[1:])

AC_cum = AC.cumsum()



for _ in range(Q):

  L,R = list(map(int,input().split()))

  print((AC_cum[R-1] - AC_cum[L-1]))

import numpy as np

import sys

buf = sys.stdin.buffer

N,Q = list(map(int,buf.readline().split()))

S = np.zeros(N+2, dtype='S1')

S[1:] = np.frombuffer(buf.read(N+1), dtype='S1')

A = (S == b'A')

C = (S == b'C')

AC = (A[:-1] & C[1:])

AC_cum = list(AC.cumsum())



for _ in range(Q):

  L,R = list(map(int,buf.readline().split()))

  print((AC_cum[R-1] - AC_cum[L-1]))

import numpy as np

N, Q = list(map(int, input().split()))
S = np.array(list("_" + eval(input())), dtype="U2")
A = S == "A"
C = S == "C"
AC = A[:-1] & C[1:]
AC_cum = AC.cumsum()
for _ in range(Q):
    L, R = list(map(int, input().split()))
    print((AC_cum[R - 1] - AC_cum[L - 1]))

import numpy as np
import sys

buf = sys.stdin.buffer
N, Q = list(map(int, buf.readline().split()))
S = np.zeros(N + 2, dtype="S1")
S[1:] = np.frombuffer(buf.read(N + 1), dtype="S1")
A = S == b"A"
C = S == b"C"
AC = A[:-1] & C[1:]
AC_cum = list(AC.cumsum())
for _ in range(Q):
    L, R = list(map(int, buf.readline().split()))
    print((AC_cum[R - 1] - AC_cum[L - 1]))

+import sys -N, Q = list(map(int, input().split())) -S = np.array(list("_" + eval(input())), dtype="U2") -A = S == "A" -C = S == "C" +buf = sys.stdin.buffer +N, Q = list(map(int, buf.readline().split())) +S = np.zeros(N + 2, dtype="S1") +S[1:] = np.frombuffer(buf.read(N + 1), dtype="S1") +A = S == b"A" +C = S == b"C" -AC_cum = AC.cumsum() +AC_cum = list(AC.cumsum()) -    L, R = list(map(int, input().split())) +    L, R = list(map(int, buf.readline().split()))