def main():

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

	S=eval(input())

	A=[0]*N

	# 累積和

	for i in range(1,N):

		A[i]=S[i-1:i+1]=="AC"

		A[i]=A[i]+A[i-1]

	# [l:r)区間の総和を求める

	for i in range(Q):

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

		print((A[r-1]-A[l-1]))

if __name__=='__main__':

	main()
import sys



def main():

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

	S=eval(input())

	A=[0]*N

	# 累積和

	for i in range(1,N):

		A[i]=S[i-1:i+1]=="AC"

		A[i]=A[i]+A[i-1]

	# [l:r)区間の総和を求める

	for i in range(Q):

		l,r=list(map(int,sys.stdin.readline().split()))

		print((A[r-1]-A[l-1]))

if __name__=='__main__':

	main()
def main():
    N, Q = list(map(int, input().split()))
    S = eval(input())
    A = [0] * N
    # 累積和
    for i in range(1, N):
        A[i] = S[i - 1 : i + 1] == "AC"
        A[i] = A[i] + A[i - 1]
    # [l:r)区間の総和を求める
    for i in range(Q):
        l, r = list(map(int, input().split()))
        print((A[r - 1] - A[l - 1]))


if __name__ == "__main__":
    main()

import sys


def main():
    N, Q = list(map(int, sys.stdin.readline().split()))
    S = eval(input())
    A = [0] * N
    # 累積和
    for i in range(1, N):
        A[i] = S[i - 1 : i + 1] == "AC"
        A[i] = A[i] + A[i - 1]
    # [l:r)区間の総和を求める
    for i in range(Q):
        l, r = list(map(int, sys.stdin.readline().split()))
        print((A[r - 1] - A[l - 1]))


if __name__ == "__main__":
    main()

+import sys + + -    N, Q = list(map(int, input().split())) +    N, Q = list(map(int, sys.stdin.readline().split())) -        l, r = list(map(int, input().split())) +        l, r = list(map(int, sys.stdin.readline().split()))