Problem:
 Score : 300 points    Problem Statement 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 1 8 3
ACACTACG
3 7
2 3
1 8      Sample Output 1 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.

Solution (Python):
"""
n = int(sys.stdin.readline())
a, b = map(int, sys.stdin.readline().split())
c = list(map(int, sys.stdin.readline().split()))
s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  

a = 100
b = 0.987654321
print('{0:06d}-{1:6f}'.format(a,b))  
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)


mod = 1000000007

if __name__ == "__main__":
    N, Q = map(int, sys.stdin.readline().split())
    origin = sys.stdin.readline()
    dp = [0 for _ in range(N + 1)]
    a_flag = False
    for i in range(N):

        if a_flag and origin[i] == "C":
            dp[i + 1] = dp[i] + 1
            a_flag = False
            continue

        if origin[i] == "A":
            a_flag = True
        else:
            a_flag = False

        dp[i + 1] = dp[i]

    for _ in range(Q):
        l, r = map(int, sys.stdin.readline().split())
        print(dp[r] - dp[l])

Solution (Python):
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(Q)]
t = [0 for i in range(N)]


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

Solution (Python):
N, Q = map(int, input().split())
S = str(input())
count = [0]*(N+1)
lists = []
for i in range(1, N):
    if S[i-1] == "A" and S[i] == "C":
        count[i] = count[i-1] + 1
    else:
        count[i] = count[i-1]
for i in range(Q):
    l, r = map(int, input().split())
    ans = count[r-1] - count[l-1]
    lists.append(ans)
for i in range(len(lists)):
    print(lists[i])

Solution (Python):

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


S = input()
question = []
ac = [0] * N
ans = []
count = 0
for _ in range(Q):
    question.append(list(map(int, input().split())))

for i in range(N):
    if S[i] == 'C' and S[i-1] == 'A':
        count += 1
        ac[i] = count
    else:
        ac[i] = count



for i in range(Q):
    start = question[i][0] - 1
    end = question[i][1] - 1
    tmp = ac[end] - ac[start]
    ans.append(tmp)

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

Solution (Python):
n,q=map(int,input().split())
s=input()
a=[0]
for i in range(1,len(s)):
  a.append(a[i-1]+s[i-1:i+1].count('AC'))
for i in range(q):
  l,r=map(int,input().split())
  print(a[r-1]-a[l-1])

Solution (Python):
N, Q = map(int, input().split())
S=input()
A=[]
AC=[0]*100001
count=0
total=0
for i in range (Q):
    A.append(list(map(int, input().split())))

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

for i in range(Q):
    total+=AC[int(A[i][1])-1]-AC[int(A[i][0])-1]
    print(total)
    total=0

Solution (Python):
N, Q = map(int, input().split())
S=input()
A=[]
AC=[0]*100001
count=0
total=0
for i in range (Q):
    A.append(list(map(int, input().split())))

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



for i in range(Q):
    total+=AC[int(A[i][1])-1]-AC[int(A[i][0])-1]
    
    
    print(total)
    total=0

Solution (Python):
n, q = map(int, input().split())
s = input()
dat_q = []
for i in range(q):
    l, r = map(int, input().split())
    dat_q.append((l, r))

c = [0] * n
for i in range(1, n):
    if s[i-1:i+1] == "AC":
        c[i] = c[i-1] + 1
    else:
        c[i] = c[i-1]
for i in range(q):
    l, r = dat_q[i][0], dat_q[i][1]
    print(c[r - 1] - c[l - 1])

Solution (Python):
N, Q = map(int, input().split())
S = list(str(input()))
LR = []
counter = [0]
for i in range(Q):
	l, r = map(int, input().split())
	
	LR.append([l - 1, r - 1])
	
for i in range(1, len(S)):
	if S[i - 1] == "A" and S[i] == "C":
		counter.append(counter[-1] + 1)
	else:
		counter.append(counter[-1])
		
for i in range(len(LR)):
	print(counter[LR[i][1]] - counter[LR[i][0]])

Solution (Python):
N,Q=map(int,input().split())
S=str(input())

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

Solution (Python):
n,q=map(int,input().split())
s=input()
ac=[0]*n
tmp=0
for i in range(1,n):
	if s[i-1]=='A' and s[i]=='C':
		tmp+=1
	ac[i]=tmp

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

Solution (Python):
import bisect

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

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

for i in range(Q):
  l, r = map(int, input().split())
  lid = bisect.bisect_left(idx, l)
  rid = bisect.bisect_right(idx, r-1)
  print(rid-lid)

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

a = [0 for i in range(n+1)]

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

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

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

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

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

Solution (Python):
n,q= map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
sa = [0]*n
for i in range(0,len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        sa[i+1] = sa[i] + 1
    else:
        sa[i+1] = sa[i]

""" A C D D D A C A C """
"""0 1 1 1 1 1 2 2 3  """
for si, syu in l:
    print(sa[syu-1] - sa[si-1])

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

Solution (Python):
import numpy as np
import sys
buf = sys.stdin.buffer
N,Q = map(int,buf.readline().split())
S = np.zeros(N+2, dtype='S1')
S[1:] = np.frombuffer(buf.read(N+1), dtype='S1')
A = (S == b'A')
C = (S == b'C')
AC = (A[:-1] & C[1:])
AC_cum = list(AC.cumsum())

for _ in range(Q):
  L,R = map(int,buf.readline().split())
  print(AC_cum[R-1] - AC_cum[L-1])

Solution (Python):
import numpy as np
N,Q = map(int,input().split())
S = np.array([b' '] + list(input()), dtype='S1')
A = (S == b'A')
C = (S == b'C')
AC = (A[:-1] & C[1:])
AC_cum = list(AC.cumsum())

for _ in range(Q):
  L,R = map(int,input().split())
  print(AC_cum[R-1] - AC_cum[L-1])

Solution (Python):
import numpy as np
N,Q = map(int,input().split())
S = np.array([b' '] + list(input()), dtype='S1')
A = (S == b'A')
C = (S == b'C')
AC = (A[:-1] & C[1:])
AC_cum = AC.cumsum()

for _ in range(Q):
  L,R = map(int,input().split())
  print(AC_cum[R-1] - AC_cum[L-1])

Solution (Python):
import numpy as np
N,Q = map(int,input().split())
S = np.array(list('_' + input()), dtype='U2')
A = (S == 'A')
C = (S == 'C')
AC = (A[:-1] & C[1:])
AC_cum = AC.cumsum()

for _ in range(Q):
  L,R = map(int,input().split())
  print(AC_cum[R-1] - AC_cum[L-1])

Solution (Python):
import numpy as np
N,Q = map(int,input().split())
S = input()
ans = np.zeros(N+1)
for i in range(N):
  ans[i+1] = ans[i] + (1 if S[i:(i+2)] == 'AC' else 0) 
for i in range(Q):
  l,r = map(int,input().split())
  print(int(ans[r-1] - ans[l-1]))

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

t = [0] * (n +1)
for i in range(n):
    t[i+1] = t[i] + (1if 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])

Solution (Python):
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])

Solution (Python):
N, Q = map(int, input().split())
S = str(input())

q_list = [0] * Q

for q in range(Q):
    q_list[q] = list(map(int, input().split()))

ac_list = [0] * len(S)
count = 0
for i in range(1, len(S)):
    if S[i - 1] == 'A' and S[i] == 'C':
        count += 1
        ac_list[i] = count
    else:
        ac_list[i] = count

for item in q_list:
    l, r = item[0], item[1]

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

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

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

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

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

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

Solution (Python):
n,q = (int(i) for i in input().split())
s = input()
ruiseki = [0]
for i in range(n-1):
    if s[i]+s[i+1] == 'AC': ruiseki.append(ruiseki[i]+1)
    else:   ruiseki.append(ruiseki[i])
lr = [[int(i) for i in input().split()] for i in range(q)]

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

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

Solution (Python):
import bisect

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

for _ in range(q):
    b,e=map(int,input().split())
    b_i = bisect.bisect_left(ac,b)
    e_i = bisect.bisect_left(ac,e)
    print(e_i-b_i)

Solution (Python):
N,Q=map(int,input().split())
S=input()
lr=[0]*Q
for i in range(Q):
    lr[i]=list(map(int,input().split()))

num=[0]*N
flag=0
for i in range(N):
    if S[i]=='A':
        flag=1
        num[i]=(num[i-1],0)[i==0]
    elif S[i]=='C' and flag==1:
        num[i]=num[i-1]+1
        flag=0
    else:
        num[i]=(num[i-1],0)[i==0]
        flag=0
for i in range(Q):
    print(num[lr[i][1]-1]-num[lr[i][0]-1])

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

Solution (Python):
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])

Solution (Python):
N, Q = input().strip().split()
N = int(N)
Q = int(Q)
S = input()
 
counts = [0 for _ in range(len(S))]
for i in range(1, len(S)):
  if S[i] == 'C' and S[i-1] == 'A':
    counts[i] = counts[i-1] + 1
  else:
    counts[i] = counts[i-1]
    
for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)-1  
  print(counts[r] - counts[l])

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

Solution (Python):
N,Q=map(int,input().split())
S=input()
ans=[0]*(N+1)
for i in range(N):
	if i!=N-1 and S[i]+S[i+1]=="AC":
		ans[i+1]=ans[i]+1
	else:
		ans[i+1]=ans[i]
for i in range(Q):
	l,r=map(int,input().split())
	print(ans[r-1]-ans[l-1])

Solution (Python):
N, Q = map(int, input().split(" "))
S = input().strip()

check = [0 for i in range(N+1)]

tmp = 0
for i in range(N):
    check[i+1] = tmp
    if S[i:i+2] == "AC":
        tmp += 1

ans = [0 for i in range(Q)]

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

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

Solution (Python):
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 q in range(Q):
  l,r=map(int,input().split())
  print(t[r-1] - t[l-1])

Solution (Python):
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])

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

Solution (Python):
from itertools import accumulate

n,q = map(int,input().split())
SS = input()
accumes = [0]
for i in range(1,len(SS)):
    if SS[i]=="C" and SS[i-1]=="A":
        accumes.append(1)
    else:
        accumes.append(0)
acuumelist = list(accumulate(accumes))
for i in range(q):
    l,r = map(int,input().split())
    print(acuumelist[r-1]-acuumelist[l-1])

Solution (Python):
n,q=map(int,input().split())
s=input()
index1=[0]*(n+2)

num=0
for i in range(len(s)):
    if s[i:i+2]=='AC':
        num+=1
    index1[i+1]=num


ans=[]

for i in range(q):
    l,r=map(int,input().split())
    if index1[l-1]==index1[l] and index1[r-1]==index1[r]:
        ans+=[index1[r]-index1[l]]
    elif index1[l-1]!=index1[l] and index1[r-1]==index1[r]:
        ans+=[index1[r]-index1[l]+1]
    elif index1[l-1]==index1[l] and index1[r-1]!=index1[r]:
        ans+=[index1[r]-index1[l]-1]
    elif index1[l-1]!=index1[l] and index1[r-1]!=index1[r]:
        ans+=[index1[r]-index1[l]]
for i in ans:
    print(i)

Solution (Python):
n,q = map(int, input().split())
s = input()
cum_list = [0]*(n+1)
a_flag = 0

for idx,i in enumerate(s,1):
    cum_list[idx] = cum_list[idx-1]
    if a_flag == 1 and i =='C':
        cum_list[idx] +=1
    if i == 'A':
        a_flag = 1
    else:
        a_flag = 0

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

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


num_ac = [0] * n
num_ac[0] = 0
if s[0] == "A" and s[1] == "C":
    num_ac[1] = 1


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

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

for a in ans:
    print(a)

Solution (Python):
from itertools import accumulate
N,Q = map(int,input().split())
S = input()
base = [0]*(N+1)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        base[i+1] = 1
base = list(accumulate(base))
for i in range(Q):
    l,r = map(int,input().split())
    print(base[r-1]-base[l-1])

Solution (Python):
import sys
input = sys.stdin.readline
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])

Solution (Python):
from itertools import accumulate
n,q=map(int,input().split())
*s,=input()
l=[0]*q
r=[0]*q
for i in range(q):
    l[i],r[i]=map(int,input().split())
a=[0]*n
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        a[i]=1
b=[0]+list(accumulate(a))
for i in range(q):
    print(b[r[i]-1]-b[l[i]-1])

Solution (Python):
from numpy import cumsum
n,q=map(int,input().split())
*s,=input()
l=[0]*q
r=[0]*q
for i in range(q):
    l[i],r[i]=map(int,input().split())
a=[0]*n
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        a[i]=1
b=[0]+list(cumsum(a))
for i in range(q):
    print(b[r[i]-1]-b[l[i]-1])

Solution (Python):
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)

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

for a in ans:
    print(a)

Solution (Python):
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])

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

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

cc = []

acc = 0

for idx in range(N):
    if S[idx - 1:idx + 1] == "AC":
        acc = acc + 1
    cc.append(acc)

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

Solution (Python):
N, Q = map(int, input().split())

S = input()
D = [0]
s = 0
for i in range(len(S) - 1):
    if S[i:i + 2] == "AC":
        s += 1
    D.append(s)

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

Solution (Python):
N, Q = [int(i) for i in 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])

Solution (Python):
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])

Solution (Python):
N, Q = map(int, input().split())
data = input()
result = [0] * N
for i in range(N-1):
  if data[i] == "A" and data[i+1] == "C":
    result[i+1] = result[i] + 1
  else:
    result[i+1] = result[i]

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

Solution (Python):
import sys

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

S = str(input())

ruisekiwa = [0]
for i in range(len(S)):
    if S[i] == 'C' and S[i-1] == 'A':
        ruisekiwa.append(ruisekiwa[-1]+1)
    else:
        ruisekiwa.append(ruisekiwa[-1])


for line in sys.stdin.readlines():
    l, r = map(int, line.strip().split())
    print(ruisekiwa[r]-ruisekiwa[l])

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

i=1
a=[0]
x=0
while i!=n:
    if s[i-1]=="A":
        if s[i]=="C":
            x=x+1
    i=i+1
    a.append(x)


i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

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

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-1] - li[x-1])

Solution (Python):
N,Q=map(int,input().split())
S=input()
AC_or_No=[0]
ans=[]
n=0

while n<=N-2:
    if S[n]=="A" and S[n+1]=="C":
        AC_or_No.append(AC_or_No[n]+1)
    else:
        AC_or_No.append(AC_or_No[n])
    n+=1

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

for i in ans:
    print(i)

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

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

cnt = [0] * 200010

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

s = [0] * 200010
flag = [0] * 200010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 :
        ans -= 1
    print("{}".format(ans))

Solution (Python):
def resolve():
    (N, Q) = list(map(int, input().split(" ")))
    S = input()
    LRs = [list(map(int, input().split(" "))) for i in range(Q)]
    mem = [0] * N
    for i in range(N-1):
        if S[i] == "A" and S[i+1] == "C":
            mem[i+1] = mem[i] + 1
        else:
            mem[i+1] = mem[i]

    for (l, r) in LRs:
        print(mem[r-1]-mem[l-1])

if '__main__' == __name__:
    resolve()

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

Solution (Python):
import numpy as np

N, Q = map(int,input().split())
S = str(input())
A = [list(map(int,input().split())) for i in range(Q)]

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')



  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""

for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

Solution (Python):
N, Q = map(int, input().split())

S = str(input())

ruisekiwa = [0]
for i in range(len(S)):
    if S[i] == 'C' and S[i-1] == 'A':
        ruisekiwa.append(ruisekiwa[-1]+1)
    else:
        ruisekiwa.append(ruisekiwa[-1])


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

Solution (Python):
n, q = map(int, input().split())
s = input()
x = [0]*(n+1)

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

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

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

where_ac = [0] * N

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

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

pos = [0] * N
i = 0
while i < N-1:
    if S[i] == 'A':
        if S[i+1] == 'C':
            pos[i+1] = 1
    i += 1

nums = [0] * (N+1)
for i in range(1, N+1):
    nums[i] += nums[i-1] + pos[i-1]

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

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

count = [0] * (N + 1)

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

ans = [0] * Q

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

for a in ans :
    print(a)

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

Solution (Python):
N, Q = map(int, input().split())
S = input()
L = [list(map(int, input().split())) for _ in range(Q)]
C = [0]*N
for i in range(1,N):
	if S[i-1] == 'A' and S[i] == 'C':
		C[i] = C[i-1] + 1
	else:
		C[i] = C[i-1]
for i in range(Q):
	print(C[L[i][1] - 1]- C[L[i][0] - 1])

Solution (Python):
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])

Solution (Python):

n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
T = [0]
cnt = 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        cnt += 1
    T.append(cnt)
for l, r in lr:
    print(T[r-1] - T[l-1])

Solution (Python):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)


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

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

j = 0

count_N = 0
count_Nr = 0
count_L = [0]
count_R = [0]
for i in range(N - 1):
	if S[i] == 'A' and S[i + 1] == 'C':
		count_N += 1
	if S[N - 2 - i] == 'A' and S[N - 1 - i] == 'C':
		count_Nr += 1
	count_L.append(count_N)
	count_R.append(count_Nr)

for i in range(Q):
	ans = count_N - count_L[l[i] - 1] - count_R[N - r[i]]
	print(ans)

Solution (Python):
N,Q = map(int,input().split())
S = input()
lst = [0] * (N+1)
before = ''
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == 'AC':
        count += 1
    lst[i+2] = count
for i in range(Q):
    l,r = map(int,input().split())
    print(lst[r]-lst[l])

Solution (Python):
N,Q = map(int,input().split())
S = input()
lst = [0] * (N+1)
before = ''
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == 'AC':
        count += 1
    lst[i+2] = count
for i in range(Q):
    l,r = map(int,input().split())
    print(lst[r]-lst[l])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,q=LI()
  s=S()

  l=[0]*(n+1)

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

  l2=[]
  for _ in range(q):
    a,b=LI()
    l2.append(l[b-1]-l[a-1])

  for x in l2:
    print(x)

main()

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

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

    if cum[l] != cum[l-1]:
        ans -= 1
    print(ans)

Solution (Python):

n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n + 1)
for i in range(n):
    if s[i : i + 2] == "AC":
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]
for i, j in arr:
    print(cnt[j - 1] - cnt[i - 1])

Solution (Python):

import sys
input = sys.stdin.readline

n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n + 1)
for i in range(n):
    if s[i : i + 2] == "AC":
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]
for i, j in arr:
    print(cnt[j - 1] - cnt[i - 1])

Solution (Python):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for i in range(q)]
s_count = [0 for i in range(n + 1)]
for i in range(n):
    s_count[i + 1] = s_count[i] + (1 if s[i:i + 2] == 'AC' else 0)

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

Solution (Python):
N, Q = (int(i) for i in input().split())
S = str(input())

ac_count = [0] *(N+1)

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

LR = []
for i in range(Q):
  LR.append([int(i) for i in input().split()])

for l,r in LR:
  ans = ac_count[r-1] - ac_count[l-1]
  print(ans)

Solution (Python):
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])

Solution (Python):
import itertools
N,K = map(int, input().split())
a = input()
l = [0]*(N-1)
for n,(i , j) in enumerate(zip(a,a[1:])):
    if i == "A" and j == "C":
        l[n] +=1
l = itertools.accumulate(l)
l = [0] + list(l)
for i in range(K):
    ta,tb = map(int, input().split())
    print(l[tb-1]-l[ta-1])

Solution (Python):
N,K = map(int, input().split())
a = input()
l = [0]*(N-1)
for n,(i , j) in enumerate(zip(a,a[1:])):
    if i == "A" and j == "C":
        l[n] +=1
l = [0]+ l
for i,n in enumerate(l[:-1]):
    l[i+1] +=l[i]
for i in range(K):
    ta,tb = map(int, input().split())
    print(l[tb-1]-l[ta-1])

Solution (Python):
N, Q = map(int, input().split())
S=input()
S1=S.split("AC")

C=[]
SC=[0]*len(S)
i=0
ac=0
for a in S1:
    
    
    C.append(len(a))

    
    
    
    
    

for c in C:
    for j in range(i,i+c):
        SC[j]=ac
    i+=c
    try:
        SC[i]=ac
        SC[i+1]=ac+1
    except:
            break
    ac+=1
    i+=2







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

Solution (Python):
N, Q = map(int, input().split())
S = input()
lis = []
for _ in range(Q):
    l, r = map(int, input().split())
    lis.append((l, r))
count = 0
count_lis = [0, 0]
pre_string = S[0]
for string in S[1:]:
    if pre_string == 'A' and string == 'C':
        count += 1
    count_lis.append(count)
    pre_string = string
for (l, r) in lis:
    print(count_lis[r] - count_lis[l])

Solution (Python):
n,m=map(int,input().split())
s=input()
l=[0]
x,y=0,0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":x+=1
    l.append(x)
l.append(x)
for i in range(m):
    a,b=map(int,input().split())
    print(l[b-1]-l[a-1])

Solution (Python):
N, Q = map(int, input().split())
S = input()
L,R = [], []
for i in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

AC = [0] * N

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

for l, r in zip(L, R):
    print(AC[r-1]-AC[l-1])

Solution (Python):
import bisect
import sys
input = sys.stdin.readline
n, q = [ int(v) for v in input().split() ]
s = input()
ac_list = []

for i in range(n-1):
	if s[i:i+2] == "AC":
		ac_list.append(i)


for i in range(q):
	l, r = [ int(v) for v in input().split() ]
	a = (bisect.bisect_left(ac_list, l-1))
	b = (bisect.bisect_right(ac_list, r-2))
	print(b-a)