Buggy python submission (verdict: Time Limit Exceeded):
num = list(map(int,input().split()))
string = input()
s_key=[]
#count=[]

for i in range(num[1]):
    s_key.append(list(map(int,input().split())))
    '''
for i in range(num[0]):
    if i==0:
        count.append(0)
    else:
        if (string[i-1]=='A' and string [i]=='C'):
            count.append(count[i-1]+1)
        else:
            count.append(count[i-1])
'''
for k in range(num[1]):
   # result=count[s_key[k][1]-1]-count[s_key[k][0]-1]
    #print(result)
   newone=string[s_key[k][0]-1:s_key[k][1]]
   print(newone.count('AC'))

Fixed submission:
num = list(map(int,input().split()))
string = input()
s_key=[]
count=[]
for i in range(num[1]):
    s_key.append(list(map(int,input().split())))
for i in range(num[0]):
    if i==0:
        count.append(0)
    else:
        if (string[i-1]=='A' and string [i]=='C'):
            count.append(count[i-1]+1)
        else:
            count.append(count[i-1])
for k in range(num[1]):
    result=count[s_key[k][1]-1]-count[s_key[k][0]-1]
    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
num = list(map(int,input().split()))
string = input()
s_key=[]
count=[]
for i in range(num[1]):
    s_key.append(list(map(int,input().split())))
for i in range(num[1]):
    count.append(0)
    for j in range(s_key[i][0]-1,s_key[i][1]-1):
        if (string[j]=='A' and string [j+1]=='C'):
            count[i]+=1
            j+=1
for k in range(num[1]):
    print(count[k])

Fixed submission:
num = list(map(int,input().split()))
string = input()
s_key=[]
count=[]
for i in range(num[1]):
    s_key.append(list(map(int,input().split())))
for i in range(num[0]):
    if i==0:
        count.append(0)
    else:
        if (string[i-1]=='A' and string [i]=='C'):
            count.append(count[i-1]+1)
        else:
            count.append(count[i-1])
for k in range(num[1]):
    result=count[s_key[k][1]-1]-count[s_key[k][0]-1]
    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = input().split(" ")
sentence = input()

for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

Fixed submission:
N,Q = map(int, input().split(" "))
sentence = input()

"""
###文章そのままの実装ー＞N,Q によりオーダーが大きくなりすぎる
for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

"""

###累積和を用いて高速に計算
#予め累積和を計算　クエリで高速回答
#ACACTGC
#0112222
AC_list = [0]*(N)
count = 0
for i in range(N-1):
	if sentence[i : i+2] == "AC":
		count += 1
	AC_list[i+1] = count

for i in range(Q):
	l,r = map(int, input().split())
	print(AC_list[r-1]-AC_list[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = input().split(" ")
sentence = input()

for i in range(int(Q)):
	count = 0
	l,r = input().split(" ")
	l = int(l)
	r = int(r)
	for j in range(r-l):
		if sentence[l-1+j] == "A":
			if sentence[l+j] == "C":
				count += 1
	print(count)

Fixed submission:
N,Q = map(int, input().split(" "))
sentence = input()

"""
###文章そのままの実装ー＞N,Q によりオーダーが大きくなりすぎる
for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

"""

###累積和を用いて高速に計算
#予め累積和を計算　クエリで高速回答
#ACACTGC
#0112222
AC_list = [0]*(N)
count = 0
for i in range(N-1):
	if sentence[i : i+2] == "AC":
		count += 1
	AC_list[i+1] = count

for i in range(Q):
	l,r = map(int, input().split())
	print(AC_list[r-1]-AC_list[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = input().split(" ")
sentence = input()

for i in range(int(Q)):
	count = 0
	l,r = input().split(" ")
	for j in range(int(r)-int(l)):
		if sentence[int(l)-1+j] == "A":
			if sentence[int(l)+j] == "C":
				count += 1
	print(count)

Fixed submission:
N,Q = map(int, input().split(" "))
sentence = input()

"""
###文章そのままの実装ー＞N,Q によりオーダーが大きくなりすぎる
for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

"""

###累積和を用いて高速に計算
#予め累積和を計算　クエリで高速回答
#ACACTGC
#0112222
AC_list = [0]*(N)
count = 0
for i in range(N-1):
	if sentence[i : i+2] == "AC":
		count += 1
	AC_list[i+1] = count

for i in range(Q):
	l,r = map(int, input().split())
	print(AC_list[r-1]-AC_list[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = input().split(" ")
sentence = input()

for i in range(int(Q)):
	count = 0
	l,r = input().split(" ")
	for j in range(int(r)-int(l)):
		if sentence[int(l)-1+j] == "A" and sentence[int(l)+j] == "C":
			count += 1

	print(count)

Fixed submission:
N,Q = map(int, input().split(" "))
sentence = input()

"""
###文章そのままの実装ー＞N,Q によりオーダーが大きくなりすぎる
for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

"""

###累積和を用いて高速に計算
#予め累積和を計算　クエリで高速回答
#ACACTGC
#0112222
AC_list = [0]*(N)
count = 0
for i in range(N-1):
	if sentence[i : i+2] == "AC":
		count += 1
	AC_list[i+1] = count

for i in range(Q):
	l,r = map(int, input().split())
	print(AC_list[r-1]-AC_list[l-1])