You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:
 - Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?

-----Notes-----
A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.
For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and  (the empty string), but not AC.

-----Constraints-----
 - 2 \leq N \leq 10^5
 - 1 \leq Q \leq 10^5
 - S is a string of length N.
 - Each character in S is A, C, G or T.
 - 1 \leq l_i < r_i \leq N

-----Input-----
Input is given from Standard Input in the following format:
N Q
S
l_1 r_1
:
l_Q r_Q

-----Output-----
Print Q lines. The i-th line should contain the answer to the i-th query.

-----Sample Input-----
8 3
ACACTACG
3 7
2 3
1 8

-----Sample Output-----
2
0
3

 - Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.
 - Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.
 - Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.

Difficulty: introductory

Starter code:

Solutions:

def main():
    N, Q = map(int,input().split())
    S = str(input())

    sum_array = [0] * 100000

    i = 0
    while i < len(S):
        if S[i] == 'A' and ((i + 1) < len(S)) and S[i + 1] == 'C':
            sum_array[i] = 1
            i += 2
        else:
            i += 1

    sum = 0
    for i in range(N):
        sum += sum_array[i]
        sum_array[i] = sum

    #print("")
    #print(sum_array)

    ans_array = [0] * Q
    for q in range(Q):
        l, r = map(int,input().split())

        l_sum = sum_array[l-1]
        if l == 1:
            l_sum = 0
        elif sum_array[l-2] != l_sum:
            l_sum = sum_array[l-2]

        r_sum = sum_array[r-1]
        if  sum_array[r-2] != r_sum:
            r_sum = sum_array[r-2]

        ans_array[q] = r_sum - l_sum
    
    for ans in ans_array:
        print(ans)

def __starting_point():
    main()
__starting_point()

# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 00:57:13 2020

@author: liang
"""

N, Q = list(map(int, input().split()))
S = input()
S += "a"
d = [0]*(N+1)
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == "AC":
        count += 1
    #print(i)
    d[i+1] = count
#print(lis)
#print(d)
for i in range(Q):
    l, r = list(map(int, input().split()))
    ans = d[r-1] - d[l-1]
    print(ans)


n,q=map(int,input().split())
s=list(input())
a=[0]*n
r=0
for ii in range(n-1):
  if s[ii]=="A" and s[ii+1]=="C":
    r+=1
  a[ii]=r
#print(a)
for _ in range(q):
	l,r=map(int,input().split())
	#print(s[l-1:r])
	print(a[r-2]-a[l-2])

a,b=map(int,input().split())
n = input()
m = [0]*a
for i in range(1,a):
  if n[i-1:i+1]=="AC":
    m[i]=m[i-1]+1
  else:
    m[i]=m[i-1]
for j in range(b):
  s,t=map(int,input().split())
  print(m[t-1]-m[s-1])

N,Q = [int(i) for i in input().split()]
S = input()
lst = [0]
for x in range(1,len(S)):
    if S[x-1:x+1]=="AC":
        lst.append(lst[x-1]+1)
    else:
        lst.append(lst[x-1])

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

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

cnt = 0
lst = []
for i in range(n):
    if s[i-1:i+1] == 'AC':
        cnt += 1
    lst.append(cnt)

for i in range(q):
    print(lst[lr[i][1] - 1] - lst[lr[i][0] - 1])

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

dp = [0]*n
temp = 0
for i in range(1,n):
    if s[i-1]=="A" and s[i] =="C":
        temp +=1
    dp[i] =temp

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


N, Q = map(int, input().split())
S = input()
cnt = [0]*N
for i in range(N-1):
  T = S[i:i+2]
  if T == 'AC':
    cnt[i+1] = cnt[i] + 1
  else:
    cnt[i+1] = cnt[i]
for i in range(Q):
  x, y = map(int, input().split())
  ans = cnt[y-1]-cnt[x-1]
  print(ans)

n, q = map(int, input().split())
s = input()
num_list = [list(map(int, input().split())) for _ in range(q)]
cnt = 0
cnt_list = [0]

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        cnt += 1
        cnt_list.append(cnt)
    else:
        cnt_list.append(cnt)

for i in range(q):
    print(cnt_list[num_list[i][1]-1] - cnt_list[num_list[i][0]-1])

n,q=map(int,input().split())
s=input()
l=[0]*n
tmp=0
for i in range(n-2,-1,-1):
    if s[i:i+2]=="AC":
        tmp+=1
    l[i]+=tmp
#print(l)
for i in range(q):
    L,R=map(int,input().split())
    print(l[L-1]-l[R-1])

N, Q = map(int, input().split())
S = input()
 
# 累積和的な発想
t = [0]*N
for i in range(N-1):
  t[i+1] = t[i]
  if S[i:i+2] == 'AC': t[i+1] += 1

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

# author:  Taichicchi
# created: 12.09.2020 19:26:19

import sys

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

S = input()

cum_ls = [0]

for i in range(1, N):
    if S[i - 1: i + 1] == "AC":
        cum_ls.append(cum_ls[i - 1] + 1)
    else:
        cum_ls.append(cum_ls[i - 1])

# print(cum_ls)

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


N,Q=list(map(int,input().split()))
S=input()
cnt=[0,0]
for i in range(1,N):
    cnt.append(cnt[-1]+S[i-1:i+1].count("AC"))
for _ in range(Q):
    l,r=list(map(int,input().split()))
    print((cnt[r]-cnt[l]))


n,q = map(int,input().split())
s=input()
a=[0]*n
for i in range(n-1):
    a[i+1]=a[i]+(1 if s[i:i+2]=="AC" else 0)

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

n,k = map(int,input().split())
s = input()
L = [0]*len(s)
for i in range(len(s)-1):
    if s[i] == "A" and s[i+1] =="C":
        L[i+1] = 1
L = [0]+L
for i in range(1,len(s)+1):
    L[i]+=L[i-1]
#print(L)
for i in range(k):
    a,b = map(int,input().split())
    print(L[b]-L[a])

n,q = map(int,input().split())
s = input()
ans = []
a = [0]*(10**5+1)
add = 0
check = False
for i in range(n):
    if check and s[i] == 'C':
        add +=1
    if s[i] == 'A':
        check = True
    else:
        check = False
    
    a[i] += add
for i in range(q):
    b,c = map(int,input().split())
    ans.append(a[c-1]-a[b-1])
for i in range(q):
    print(ans[i])

N,Q=list(map(int,input().split()))
S=input()
li=[0]
A=False
ans=0
import copy
for i in range(N):
    if A==True:
        if S[i]=="C":
            ans+=1
        A=False
    if S[i]=="A":
        A=True
    li.append(copy.copy(ans))
for j in range(Q):
    a,b=list(map(int,input().split()))
    print((li[b]-li[a]))


N,Q = list(map(int,input().split()))
S = input()
lr = [list(map(int,input().split()))for _ in range(Q)]
l = [lr[i][0] for i in range(Q)]
r = [lr[i][1] for i in range(Q)]
#print(lr)
#print(l)
#print(r)

c = [0] * N
cnt = 0

for i in range(N-1):
    if S[i:i+2] == 'AC':
        c[i+1]=c[i]+1
    else:
        c[i+1]=c[i]
    #c[i] = S[:i].count('AC')
    #countを使わずにiまでの合計値をリスト化

#print(c)

for i,j in zip(l,r):
    #print(sum(c[:j])-sum(c[:i]))
    #l,r = map(int,input().split())
    print((c[j-1]-c[i-1]))
    #合計値を利用してsumを使わずに差を表示して計算減させる
    #リストを要素ごとに分けるのは初めにやっておいて大丈夫


n, q = map(int, input().split())
s = input()
t = [0] * (n+1)

for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)

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

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

lsline = []
for i in range(Q):
    lsline.append(list(map(int,input().split())))

lsAC = [0,0]
AC = 0
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        AC += 1
    lsAC.append(AC)
for i in range(Q):
    print(lsAC[lsline[i][1]]-lsAC[lsline[i][0]])

import sys

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

cnt = [0]*(N+1)
wasA = False

for i in range(0,N):
  if wasA and S[i] == "C":
    cnt[i+1] = cnt[i] + 1
    wasA = False
  elif S[i] == "A":
    cnt[i+1] = cnt[i]
    wasA = True
  else:
    cnt[i+1] = cnt[i]
    wasA = False

#print(cnt)    

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

N,Q = map(int,input().split())
S = input()
c = []
count = 0
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        count += 1
    c.append(count)
for i in range(Q):
    l,r = map(int,input().split())
    if l == 1:
        print(c[r-2]-0)
    else:
        print(c[r-2]-c[l-2])

n,q = map(int,input().split())
s = input()
cusumList = [0]
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        cusumList.append(cusumList[i]+1)
    else:
        cusumList.append(cusumList[i])

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

N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split()))for _ in range(Q)]
l = [lr[i][0] for i in range(Q)]
r = [lr[i][1] for i in range(Q)]
#print(lr)
#print(l)
#print(r)

c = [0] * N
cnt = 0

for i in range(N-1):
    if S[i:i+2] == 'AC':
        c[i+1]=c[i]+1
    else:
        c[i+1]=c[i]
    #c[i] = S[:i].count('AC')

#print(c)

for i,j in zip(l,r):
    #print(sum(c[:j])-sum(c[:i]))
    #l,r = map(int,input().split())
    print(c[j-1]-c[i-1])

N, Q = map(int, input().split())
S = input()
 
# 累積和的な発想
t = [0]*N
for i in range(N-1):
  t[i+1] = t[i]
  if S[i:i+2] == 'AC': t[i+1] += 1

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

N,Q = map(int,input().split())
S = input()
t = [0]*(N+1)

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

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

csum = [0]
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        csum.append(csum[-1]+1)
    else:
        csum.append(csum[-1])
for l, r in lr:
    print(csum[r-1]-csum[l-1])

import numpy as np

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

X = np.zeros(N+1, dtype='int64')
tmp = 1 # いま何文字目か
while S.find('AC') >= 0 and tmp < N:
    i = S.find('AC')
    X[tmp+i] += 1 # AC の A がある場所に 1 を加算
    S = S[i+2:] # 2文字進める
    tmp += i + 2
SUM = X.cumsum()

for _ in range(Q):
    l, r = map(int, input().split())
    # A の右隣の C まで含まれていないといけないので、
    # r文字目ではなく、r-1文字目までで考える
    print(SUM[r-1] - SUM[l-1])

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

d = [0]*100100
e = [0]*100100

for i in range(0,n-1):
	if s[i] == 'A' and s[i+1]=='C':
		d[i+1]=1

for i in range(0,n+1):
	d[i+1] += d[i]

for i in range(0,q):
	l,r = list(map(int,input().split()))
	l-=1
	lefNum = d[l]

	rigNum = d[r]
	if r < n and s[r-1] == 'A' and s[r] =='C':
		rigNum-=1

	ans = rigNum - lefNum
	print(ans)


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

c = [0]
for i in range(1, n):
    if s[i-1:i+1] == "AC":
        c.append(c[-1]+1)
    else:
        c.append(c[-1])

for _ in range(q):
    l, r = map(int, input().split())
    print(c[r-1] - c[l-1])

n,q=map(int,input().split())
s=input()
a=[0,0]
for l in range(1,n):
    if s[l-1]=='A' and s[l]=='C':
        a.append(a[l]+1)
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y]-a[x])

n, q = list(map(int, input().split()))
s = input()
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i : i + 2] == "AC" else 0)

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



N,Q=map(int,input().split())
S=input()
LR=[list(map(int,input().split())) for _ in range(Q)]

F=[0]*len(S)
for i in range(N-1):
    F[i+1]+=F[i]+(1 if S[i:i+2]=='AC' else 0)
    #print(i,F,S[i:i+2])
for l,r in LR:
    print(F[r-1]-F[l-1])

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

total = [0] * N
for i in range(1,N):
	total[i] = total[i-1]
	if S[i-1] == 'A' and S[i] == 'C':
		total[i] += 1

for q in range(Q):
	L,R = list(map(int, input().split()))
	L -=1
	R -=1

	count = total[R] - total[L]
	print(count)


n, q = map(int, input().split())
s = input()
a = [list(map(int, input().split())) for i in range(q)]

c = [0] * n
for i in range(1,n):
  c[i] = c[i-1] + (s[i-1]+s[i] == 'AC')

for x in a:
  print(c[x[1]-1]-c[x[0]-1])

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,q=input2()
B=str(input())
LR=[input_array() for _ in range(q)]

# E=["A","C","G","T"]
T=[0]*(n+1) #1文字目〜n文字目までに出現する"AC"数の累積和

for i in range(n):
	if B[i:i+2] == "AC":	
		T[i+1] = T[i]+1
	else:
		T[i+1]=T[i]
for lr in LR:
	st=lr[0]-1
	fi=lr[1]-1
	print(T[fi]-T[st])

N, Q = [int(x) for x in input().split(" ")]

s = input()
AinAC = [0]
CinAC = [0]
c = 0
for i in range(len(s) - 1):
  if s[i] == "A" and s[i + 1] == "C":
    CinAC.append(c)
    c += 1
    AinAC.append(c)
  else:
    AinAC.append(c)
    CinAC.append(c)
else:
  AinAC.append(c)
  CinAC.append(c)

ans = []
for i in range(Q):
  l, r = [int(x) for x in input().split(" ")]
  right = min([AinAC[r], CinAC[r]])
  left = max([AinAC[l - 1], CinAC[l - 1]])
  ans.append(str(right - left))

print(("\n".join(ans)))


# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, Q, S, LRi):
    cumulative_sum = [0, 0]
    for i in range(1, N):
        tmp = cumulative_sum[-1]
        if S[i - 1:i + 1] == 'AC':
            tmp += 1
        cumulative_sum.append(tmp)

    for l, r in LRi:
        print((cumulative_sum[r] - cumulative_sum[l]))


def __starting_point():
    N, Q = list(map(int, input().split()))
    S = input()
    LRi = [[int(i) for i in input().split()] for _ in range(Q)]
    solve(N, Q, S, LRi)

    # # test
    # from random import randint
    # from func import random_str
    # N, Q = 10 ** 5, 10 ** 5
    # S = random_str(N, 'ACGT')
    # LRi = [sorted([randint(1, N) for _ in range(2)]) for _ in range(Q)]
    # solve(N, Q, S, LRi)

__starting_point()

N, Q = map(int, input().split())
S = input()
LR = [tuple(map(int, input().split())) for _ in range(Q)]

cum = [0]*(N+1)

cnt = 0
for i in range(1,N):
    if S[i-1] == 'A' and S[i] == 'C':
        cnt += 1
    cum[i] = cnt

ans = []
for l, r in LR:
    result = cum[r-1] - cum[l-1]
    ans.append(result)

print(*ans, sep='\n')


N, Q = [int(i) for i in input().split()]
S = input()

cs = [0]
for i in range(1, N):
  if S[i-1] + S[i] == 'AC':
    cs.append(cs[i-1] + 1)
  else:
    cs.append(cs[i-1])

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


from itertools import accumulate

n, q = list(map(int, input().split()))
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

ac_list = [0]*n

for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_list[i] = 1

ac_sum = list(accumulate(ac_list))

for l, r in lr:
    l -= 1
    r -= 1
    if l == 0:
        print((ac_sum[r-1]))
        continue
    print((ac_sum[r-1] - ac_sum[l-1]))


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

class bit:
  def __init__(self, N):
    self.__N = N
    self.__a = [0] * N
  def add_(self, x, v):
    x += 1
    while x < self.__N:
      self.__a[x] += v
      x += x & -x
  def show_(self):
    print(self.__a[1:])
    
  def sum_(self, x):
    ans = 0
    while x > 0:
      ans += self.__a[x]
      x -= x & -x
    return ans
  def sub_sum_(self, x, y):
    return self.sum_(y) - self.sum_(x)
prev = "0"
BIT = bit(N)
for i, val in enumerate(S):
  if prev == "A" and val == "C":
    BIT.add_(i-1, 1)
  prev = val
for i in range(Q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  print(BIT.sub_sum_(x,y))

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

s = input()

v = [0] * n

for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        v[i] = 1

m = [0] * (n + 1)
for i in range(n):
    m[i + 1] = m[i] + v[i]


for i in range(q):
    l, r = list(map(int, input().split()))
    l -= 1
    ans = 0
    if r - l < 2:
        ans = 1
    else:
        ans = m[r] - m[l]
        if v[r - 1] == 1:
            ans -= 1
    print(ans)


N,Q = map(int,input().rstrip().split())
S = input().rstrip()
a = [0]*N
for i in range(N):
    if i > 1:
        a[i] = a[i-1]
    if i != 0 and S[i-1]=='A' and S[i] == 'C':
        a[i] += 1
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(a[r-1]-a[l-1])

N, Q = list(map(int, input().split()))
S = input()
t = [0]*(N+1)

for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

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


import sys

input = sys.stdin.readline

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

S = input()
S = S.replace('\n','')
s_list = list(S)

l = [0 for i in range(q)]
r = [0 for i in range(q)]
for i in range(q):
    l[i], r[i] = map(int, input().split())

ac_sum_list = [0 for i in range(len(s_list))]
tmp = ""
ac_sum = 0
for i,s in enumerate(s_list):
    if tmp + s == "AC":
        ac_sum += 1
    ac_sum_list[i] = ac_sum
    tmp = s


for i in range(q):
    l_index = l[i]
    r_index = r[i]
    l_ac = ac_sum_list[l_index-1]
    r_ac = ac_sum_list[r_index-1]
    print(r_ac - l_ac)

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


cum_sum = [0] * N
count_AC = [0] * N

for i in range(N-1):
    if (S[i] + S[i+1]) == "AC":

        count_AC[i+1] = 2
        cum_sum[i+1] = 2
    cum_sum[i+1] = cum_sum[i] + cum_sum[i+1]


for _ in range(Q):
    l,r = map(int, input().split())
    l = l - 1
    r = r - 1
    print((cum_sum[r]//2)-(cum_sum[l]//2))   

n,q=map(int,input().split())
ans = [0]*(n)
S = input()
for i in range(n-1):
  tmp = 0
  if S[i] == "A" and S[i+1] == "C":
    tmp = 1
  ans[i+1] = ans[i]+tmp
for i in range(q):
  l,r = map(int,input().split())
  print(ans[r-1]-ans[l-1])

n, q = map(int, input().split())
s = input()
lr = list(list(map(int, input().split()) for _ in range(q)))

c = [0]
for i in range(1, n):
    if s[i-1:i+1] == "AC":
        c.append(c[-1]+1)
    else:
        c.append(c[-1])

for l, r in lr:
    print(c[r-1] - c[l-1])

N,K = list(map(int,input().split()))
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = list(map(int,input().split()))
    print((ans[sp-1]-ans[st-1]))


#!/usr/bin/env python3

#import
#import math
#import numpy as np
N, Q = list(map(int, input().split()))
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

s = [0] * N

for i in range(1, N):
    s[i] = s[i - 1]
    if S[i - 1] == "A" and S[i] == "C":
        s[i] += 1

for l, r in lr:
    print((s[r - 1] - s[l - 1]))
    


from bisect import bisect_left
from bisect import bisect_right
n, q = list(map(int, input().split()))
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]

ac = []
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac.append(i)

if ac == []:
    for i in range(q):
        print((0))
    return

for l, r in lr:
    l -= 1
    r -= 1
    li = bisect_left(ac, l)
    ri = bisect_right(ac, r)
    if li == ri:
        print((0))
    elif r > ac[ri-1]:
        print((ri-li))
    else:
        print((ri-li-1))


#n = int(input())
n, q = list(map(int, input().split()))
#bl = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
s = input()
acnum = [0]*(n+1)
for i in range(2, n+1):
    if s[i-2:i] == 'AC':
        acnum[i] += acnum[i-1]+1
    else:
        acnum[i] += acnum[i-1]

for i in range(q):
    l, r = list(map(int, input().split()))
    print((acnum[r]-acnum[l]))


n, q = map(int, input().split())
S = input()
*LR, = (map(int, input().split()) for _ in range(q))
 
A = [0] * n
for i in range(1, n):
    A[i] = A[i-1] + (S[i-1:i+1]=='AC')
for l, r in LR:
    print(A[r-1]-A[l-1])

n,q = map(int,input().split())
s = input()
cnt = [0]*n
for i in range(1,n):
    cnt[i] += cnt[i-1]
    if s[i-1:i+1] == "AC":
        cnt[i]+=1
for i in range(q):
    l,r = map(int,input().split())
    print(cnt[r-1]-cnt[l-1])

N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
cnt = 0
for i in range(1, N):
    if S[-i] == "C" and S[-i-1] == "A":
            cnt += 1
    dp[N-i] = cnt
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if r[q] < N:
        if S[r[q]] == "A" and S[r[q] + 1] == "C":
            ans -= 1
    print(ans)

import bisect
n,q = map(int, input().split(" "))
s = input()
lr = [list(map(int, input().split(" "))) for i in range(q)]
a = []
for i in range(n-1):
  if s[i] +s[i+1]== 'AC':
    a.append(i+1)
for l, r in lr:
  print(bisect.bisect(a, r-1) - bisect.bisect(a, l-0.1))

n,q = map(int,input().split())
s = input()
cnt = [0]*n
for i in range(1,n):
    cnt[i] += cnt[i-1]
    if s[i-1:i+1] == "AC":
        cnt[i]+=1
for i in range(q):
    l,r = map(int,input().split())
    print(cnt[r-1]-cnt[l-1])

n, q = map(int, input().split())
S = input()
flag = False
L = [0 for _ in range(n)]
cnt = 0
for i, s in enumerate(S):
    if flag:
        if s == "C":
            cnt += 1
        flag = False
    if s == "A":
        flag = True
    L[i] = cnt

for _ in range(q):
    l, r = map(lambda x: int(x) - 1, input().split())
    print(L[r] - L[l])

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

cs = [0] * N
cnt = 0
for i in range(1, N):
    if S[i-1:i+1] == "AC":
        cnt += 1
    cs[i] = cnt

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


import numpy as np

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

qs = []
for i in range(q):
    qs.append(list(map(int,input().split())))

ls = [0]
count = 0
for i in range(1,n):
    if s[i-1:i+1]=='AC':
        count +=1
    ls.append(count)

for ques in qs:
    print(ls[ques[1]-1]-ls[ques[0]-1])

N, Q = map(int, input().split())
S = input()
ls = [0]
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ls.append(ls[i]+1)
    else:
        ls.append(ls[i])

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

N, Q = map(int, input().split())
S = input()
 
# 累積和的な発想
t = [0]*(N+1) # t[0]=t[1]=0
for i in range(N-1):
  t[i+2] = t[i+1]
  if S[i:i+2] == 'AC': t[i+2] += 1
    
for _ in range(Q):
  l,r = map(int, input().split())
  print(t[r] - t[l])

n,q=list(map(int,input().split()))
s=input()
lr=[list(map(int,input().split())) for i in range(q)]

rui=[0]*(n+1)
tmp=0
for i in range(len(s)):
  if s[i-1] == 'A' and s[i] == 'C':
    tmp += 1
  rui[i] = tmp

for i in range(q):
  print((rui[lr[i][1]-1] - rui[lr[i][0]-1]))


N, Q = list(map(int, input().split()))
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = list(map(int, input().split()))
    print((t[r-1] - t[l-1]))


##初期値設定##
N, Q = map(int, input().split())
S = input()
dl=[]
dr=[]
for i in range(Q):
    line = list(map(int, input().split()))
    dl.append(line[0])
    dr.append(line[1])

##ACの個数配列計算##
a=[]
for i in range(N-1):
    tmp_S = S[i:i+2]
    if tmp_S == "AC":
        a.append(1)
    else:
        a.append(0)

##累積和計算##
s = [0]
for i in range(len(a)):
    s.append(s[i]+a[i])

##解答算出##
ans=[]
for l, r in zip(dl, dr):
    ans.append(s[r-1]-s[l-1])

for i in range(Q):
    print(ans[i])

n,q = map(int,input().split())
s = input()
count = [0] * (n+1)
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        count[i+1] = count[i] + 1
    else:
        count[i+1] = count[i]
for i in range(q):
    l,r = map(int,input().split())
    print(count[r-1] - count[l-1])

n, q = map(int, input().split())
s = input()
ac = {1:0}
k = 0
for i in range(1, n):
  if s[i - 1:i + 1] == 'AC':
    k += 1
  ac[i + 1] = k
ans = []
for i in range(q):
  l, r = map(int, input().split())
  ans.append(ac[r] - ac[l])
for e in ans:
  print(e)

N,Q=list(map(int, input().split()))
S=input()
Ssum=[0]*N

now=S[0]
cnt=0
for i in range(1,N):
	next=S[i]
	if now=="A" and next=="C":
		cnt+=1
	Ssum[i]=cnt
	now=next

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



# author:  Taichicchi
# created: 26.09.2020 13:43:12

import sys

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

S = input()

ls = [0]

for i in range(N):
    if i == 0:
        ls.append(0)
    else:
        if S[i - 1:i + 1] == "AC":
            ls.append(ls[-1] + 1)
        else:
            ls.append(ls[-1])

for q in range(Q):
    l, r = map(int, input().split())

    print(ls[r] - ls[l])

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

# 累積和
L = [0]*(N+1) # L[0]=L[1]=0
for i in range(N-1):
  L[i+2] = L[i+1]
  if S[i:i+2] == 'AC': L[i+2] += 1
    
for i in range(Q):
  l = lr[i][0]
  r = lr[i][1]
  print(L[r] - L[l])

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

l = [0]*Q
r = [0]*Q

cntac = [0]

for t in range(1,N) :
    if S[t-1:t+1] == "AC":
        cntac.append(cntac[t-1]+1)
    else :
        cntac.append(cntac[t-1])

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

n, q = map(int, input().split())
s = input()
ss = [0]*n
cnt = 0

for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    cnt +=1    
    ss[i+1] += cnt    
  else:
    ss[i+1] = ss[i]

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

n, q = map(int, input().split())
s = list(input())
num = [0] * n
count = 0
for i in range(n - 1):
    if s[i] == 'A' and s[i + 1] == 'C':
        count += 1
    num[i + 1] = count
for i in range(q):
    l, r = map(int, input().split())
    ans = num[r - 1] - num[l - 1]
    print(ans)

N, Q = map(int, input().split())
S = input()
t = [0 for _ in range(len(S)+1)]

for i in range(N):
    t[i+1] = t[i] + (1 if S[i:(i+2)] == "AC" else 0)
    
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1]-t[l-1])

N,Q=map(int,input().split())
S=input()
B=[0]*N
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        B[i]=B[i-1]+1
    else:
        B[i]=B[i-1]
for i in range(Q):
    l,r=map(int,input().split())
    print(B[r-1]-B[l-1])

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

nums = [0]*n
for i in range(1,n):
  if s[i] == "C":
    if s[i-1] == "A": nums[i] += 1
  nums[i] += nums[i-1]
  
for _ in range(q):
  l,r = map(lambda x: int(x)-1, input().split())
  print(nums[r]-nums[l])

n,q=list(map(int,input().split()))
s=input()
con=[0]
c=False
for i in range(n):
    if s[i]=='A':
        c=True
        con.append(con[-1])
        continue
    if c:
        if s[i]=='C':
            con.append(con[-1]+1)
            c=False
            continue
        else:
            con.append(con[-1])
            c=False
            continue
    con.append(con[-1])    
for j in range(q):
    l,r=list(map(int,input().split()))
    print((max(0,con[r]-con[l])))



n,q=list(map(int,input().split()))
s=input()
lr=[list(map(int,input().split())) for i in range(q)]

rui=[0]*(n+1)
tmp=0
for i in range(n):
  if s[i-1] == 'A' and s[i] == 'C':
    tmp += 1
  rui[i] = tmp

for l,r in lr:
  print((rui[r-1] - rui[l-1]))


N, Q = map(int, input().split())
S = input()
cnt = [0]*(N+1)

for i in range(1, N):
    if S[i - 1] == 'A' and S[i] == 'C':
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]
        
for i in range(Q):
    L, R = map(int, input().split())
    print(cnt[R] - cnt[L])

n,q=[int(i) for i in input().split()]
s=input()


dp=[0]*(n)
ans=0
for i in range(1,n):
    if s[i-1]=="A" and s[i]=="C":
        ans=ans+1
    dp[i]=ans

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


n, q = list(map(int, input().split()))
s = input()
ls = [list(map(int, input().split())) for i in range(q)]
d = [0]
pre = 0
c = 0

for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        d.append(d[i]+1)
    else:
        d.append(d[i])



for start, end in ls:
    print((d[end-1]-d[start-1]))


n,q=map(int,input().split())
s=list(map(str,input()))
arr=[list(map(int,input().split())) for j in range(q)]

result=[0]
cnt=0
for i in range(1,len(s)):
	if s[i-1]+s[i]=="AC":
		cnt+=1
		result.append(cnt)
	elif s[i-1]+s[i]!="AC":
		result.append(cnt)
        

for a,b in arr:
	print(result[b-1]-result[a-1])

N, Q = list(map(int, input().split()))
S = input()
t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l,r = list(map(int, input().split()))
    print((t[r-1] - t[l-1])) 



n,q=list(map(int,input().split()))
s=input()
l=[0 for i in range(len(s))]

for i in range(len(s)-1):
  if s[i]=="A" and s[i+1]=="C":
    l[i+1]=l[i]+1
  else:
    l[i+1]=l[i]


for i in range(q):
  left,right=list(map(int,input().split()))
  print((l[right-1]-l[left-1]))


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

a = [0] * N
c = 0

for i in range(N-1):
    if S[i:i+2] == "AC":
        c += 1
    a[i + 1] = c

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

n, q = map(int, input().split())
s = input()
ac = {1:0, }
k = 0
for i in range(1, n):
  if s[i - 1:i + 1] == 'AC':
    k += 1
  ac[i + 1] = k
ans = []
for i in range(q):
  l, r = map(int, input().split())
  ans.append(ac[r] - ac[l])
for e in ans:
  print(e)

n, q = list(map(int, input().split()))
s = input()
sl = [0]
for i in range(1, n):
    if s[i-1:i+1] == 'AC':
        sl.append(sl[i-1]+1)
    else:
        sl.append(sl[i-1])

for _ in range(q):
    l, r = list(map(int, input().split()))
    print((sl[r-1]-sl[l-1]))


from bisect import bisect_left, bisect_right

def main():
    N, Q = list(map(int, input().split()))
    S = input()
    s = []
    for i in range(N-1):
        if S[i] + S[i+1] == 'AC':
            s.append(i)
    
    for q in range(Q):
        l, r = list(map(int, input().split()))
        ans = bisect_left(s, r-1) - bisect_left(s, l-1)
        print(ans)


def __starting_point():
    main()

__starting_point()

import numpy as np

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

s_l = np.zeros(N + 1)
for i, s in enumerate(S):
    if i + 1 < N and s == "A" and S[i + 1] == "C":
        s_l[i + 1] = s_l[i] + 1
    else:
        s_l[i + 1] = s_l[i]

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


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

lr = [list(map(int,input().split())) for i in range(q)]

acm = [0]*(n+1)

for i in range(1,n):
    if(s[i-1]=='A' and s[i]=='C'):
        acm[i] = acm[i-1] + 1 
    else:
        acm[i]=acm[i-1]

acm[n] = acm[n-1] 

for lis in lr:
    l,r =lis
    print((acm[r-1]-acm[l-1]))


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

d = [0]*100100
e = [0]*100100

for i in range(0,n-1):
	if s[i] == 'A' and s[i+1]=='C':
		d[i+1]=1

for i in range(0,n+1):
	d[i+1] += d[i]

for i in range(0,q):
	l,r = list(map(int,input().split()))
	l-=1
	lefNum = d[l]
	#if l > 0 and s[l-1] == 'A' and s[l] == 'C':
	#	lefNum-=1

	rigNum = d[r]
	if r < n and s[r-1] == 'A' and s[r] =='C':
		rigNum-=1
	#r-=1
	ans = rigNum - lefNum
	#print(l,r,ans)
	print(ans)

#for i in range(0,n):
#	print(i,d[i])
#	print(d[r]-d[l])


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

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

# 累積和 s を計算
c = [0 for _ in range(N + 1)]
for i in range(1, N):
    a = 0
    if S[i-1:i+1] == 'AC':
        a = 1
    c[i + 1] = c[i] + a

# 各クエリに答える
for _ in range(Q):
    l, r = list(map(int, input().split()))
    l -= 1
    result = c[r] - c[l]
    if l > 0 and S[l-1:l+1] == 'AC':
        result -= 1
    print(result)
    


from bisect import bisect_left
n, q = map(int, input().split())
s = list(input())
L = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        L.append(i)
ans = []
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    st = bisect_left(L, l)
    fi = bisect_left(L, r)
    ans.append(fi - st)

for i in ans:
    print(i)

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, Q = list(map(int, readline().split()))
    S = readline().strip()
    (*LR,) = list(map(int, read().split()))

    vec = [0] * (N + 1)
    for i in range(N - 1):
        vec[i + 1] = vec[i]
        if S[i] == 'A' and S[i + 1] == 'C':
            vec[i + 1] += 1

    ans = [0] * Q
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        l -= 1
        r -= 1
        ans[i] = vec[r] - vec[l]

    print(('\n'.join(map(str, ans))))
    return


def __starting_point():
    main()

__starting_point()

n,q = map(int,input().split())
s = input()
s = s.replace('AC','ac')
t = [0] * n
r = 0
for i in range(n):
    if s[i] == 'c':
        r += 1
    t[i] = r
for i in range(q):
    l,r = map(int,input().split())
    print(t[r-1]-t[l-1])