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

s=eval(input())

ac=[0]*(n)

for i in range(len(s)-1):

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

        ac[i+1]=ac[i]+1

    else:

        ac[i+1]=ac[i]

#print(ac)

# 01122233

# ACACTACG

for i in range(q):

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

    #print(ac[l:r])

    print((ac[r-1]-ac[l-1]))
#import pysnooper

#import os,re,sys,operator,math,heapq,string

from collections import Counter,deque

#from operator import itemgetter

#from itertools import accumulate,combinations,groupby,combinations_with_replacement

from sys import stdin,setrecursionlimit

#from copy import deepcopy



setrecursionlimit(10**6)

input=stdin.readline



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

s=input().rstrip()

ac=[0]*(n+1)

for i in range(n-1):

    if s[i]+s[i+1]=="AC":

        ac[i+1]=ac[i]+1

    else:

        ac[i+1]=ac[i]

for i in range(q):

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

    print((ac[r-1]-ac[l-1]))
n, q = list(map(int, input().split()))
s = eval(input())
ac = [0] * (n)
for i in range(len(s) - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ac[i + 1] = ac[i] + 1
    else:
        ac[i + 1] = ac[i]
# print(ac)
# 01122233
# ACACTACG
for i in range(q):
    l, r = list(map(int, input().split()))
    # print(ac[l:r])
    print((ac[r - 1] - ac[l - 1]))

# import pysnooper
# import os,re,sys,operator,math,heapq,string
from collections import Counter, deque

# from operator import itemgetter
# from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin, setrecursionlimit

# from copy import deepcopy
setrecursionlimit(10**6)
input = stdin.readline
n, q = list(map(int, input().split()))
s = input().rstrip()
ac = [0] * (n + 1)
for i in range(n - 1):
    if s[i] + s[i + 1] == "AC":
        ac[i + 1] = ac[i] + 1
    else:
        ac[i + 1] = ac[i]
for i in range(q):
    l, r = list(map(int, input().split()))
    print((ac[r - 1] - ac[l - 1]))

+# import pysnooper +# import os,re,sys,operator,math,heapq,string +from collections import Counter, deque + +# from operator import itemgetter +# from itertools import accumulate,combinations,groupby,combinations_with_replacement +from sys import stdin, setrecursionlimit + +# from copy import deepcopy +setrecursionlimit(10**6) +input = stdin.readline -s = eval(input()) -ac = [0] * (n) -for i in range(len(s) - 1): -    if s[i] == "A" and s[i + 1] == "C": +s = input().rstrip() +ac = [0] * (n + 1) +for i in range(n - 1): +    if s[i] + s[i + 1] == "AC": -# print(ac) -# 01122233 -# ACACTACG -    # print(ac[l:r])