from itertools import accumulate

n,q=list(map(int,input().split()))

s=eval(input())

l=[0]*q

r=[0]*q

for i in range(q):

    l[i],r[i]=list(map(int,input().split()))

L=min(l)

R=max(r)

#前処理

A=[]

for i in range(L,R):

    if s[i-1]=="A"and s[i]=="C":

        A.append(1)

    else:

        A.append(0)

A.append(0)

s=[0]+A

S=list(accumulate(s))

#累積和

for i in range(q):

    print((S[r[i]-L]-S[l[i]-L]))

    





        



from itertools import accumulate

n,q=list(map(int,input().split()))

s=list(eval(input()))

l=[]

r=[]

for i in range(q):

  o,p=list(map(int,input().split()))

  l.append(o)

  r.append(p)

  

ruiseki=[]

for i in range(n-1):

  if s[i]=="A" and s[i+1]=="C":

    ruiseki.append(1)

  else:

    ruiseki.append(0)

ruiseki=[0]+list(accumulate(ruiseki))



for i in range(q):

  print((ruiseki[r[i]-1]-ruiseki[l[i]-1]))

  

    
from itertools import accumulate

n, q = list(map(int, input().split()))
s = eval(input())
l = [0] * q
r = [0] * q
for i in range(q):
    l[i], r[i] = list(map(int, input().split()))
L = min(l)
R = max(r)
# 前処理
A = []
for i in range(L, R):
    if s[i - 1] == "A" and s[i] == "C":
        A.append(1)
    else:
        A.append(0)
A.append(0)
s = [0] + A
S = list(accumulate(s))
# 累積和
for i in range(q):
    print((S[r[i] - L] - S[l[i] - L]))

from itertools import accumulate

n, q = list(map(int, input().split()))
s = list(eval(input()))
l = []
r = []
for i in range(q):
    o, p = list(map(int, input().split()))
    l.append(o)
    r.append(p)
ruiseki = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ruiseki.append(1)
    else:
        ruiseki.append(0)
ruiseki = [0] + list(accumulate(ruiseki))
for i in range(q):
    print((ruiseki[r[i] - 1] - ruiseki[l[i] - 1]))

-s = eval(input()) -l = [0] * q -r = [0] * q +s = list(eval(input())) +l = [] +r = [] -    l[i], r[i] = list(map(int, input().split())) -L = min(l) -R = max(r) -# 前処理 -A = [] -for i in range(L, R): -    if s[i - 1] == "A" and s[i] == "C": -        A.append(1) +    o, p = list(map(int, input().split())) +    l.append(o) +    r.append(p) +ruiseki = [] +for i in range(n - 1): +    if s[i] == "A" and s[i + 1] == "C": +        ruiseki.append(1) -        A.append(0) -A.append(0) -s = [0] + A -S = list(accumulate(s)) -# 累積和 +        ruiseki.append(0) +ruiseki = [0] + list(accumulate(ruiseki)) -    print((S[r[i] - L] - S[l[i] - L])) +    print((ruiseki[r[i] - 1] - ruiseki[l[i] - 1]))