CodeEff/ECCO huggingface dataset:
# Original solution
import sys


def inp():
    return sys.stdin.readline().strip()


n, q = list(map(int, inp().split()))
s = inp()
a = []

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

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

# Optimized solution
import sys


def inp():
    return sys.stdin.readline().strip()


n, q = list(map(int, inp().split()))
s = inp()
a = [0] * n

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

for _ in range(q):
    l, r = list(map(int, inp().split()))
    print((a[r-1] - a[l-1]))
# Original solution
N, Q = input().strip().split(' ')
S = input().strip()

for i in range(int(Q)):
    l, r = tuple(map(int, input().strip().split(' ')))
    print((S[l-1:r].count('AC')))


# Optimized solution
dd = input().strip().split(' ')
N, Q = tuple(map(int, dd))
S = input().strip()

ac_indicies = []
cp = S.find('AC')
while cp != -1:
    ac_indicies.append(cp)
    cp = S.find('AC', cp + 1)

min_i = 0
ac = ac_indicies + [N]
l_index = []
for i in range(N):
    if i > ac[min_i]:
        min_i += 1
    l_index.append(min_i)

total = len(ac_indicies)
for i in range(int(Q)):
    l, r = tuple(map(int, input().strip().split(' ')))
    print((l_index[r-1] - l_index[l-1]))
# Original solution
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

m = [0 for _ in range(len(s) + 1)]

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

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r - 1

    if c == 0:
        print((0))
        continue
    print((m[1:][r - 1] - m[l]))


# Optimized solution
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

m = [0 for _ in range(len(s) + 1)]

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

for i in range(q):
    l, r = read_line(int, int)

    if c == 0:
        print((0))
        continue
    print((m[r - 1] - m[l - 1]))
# Original solution
n, q = map(int, input().split())
s = input()
ans = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    substr = str(s[l - 1:r])
    ans[i] = substr.count("AC")
print(*ans, sep='\n')


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

ans = [0] * q

for i in range(q):
    l, r = map(int, input().split())
    ans[i] = cum[r] - cum[l]
print(*ans, sep='\n')
# Original solution
import bisect
import re
import sys

N, Q = list(map(int, input().split()))
S = sys.stdin.readline()
P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

r = re.compile('AC')
a = [x.start() for x in r.finditer(S)]

if a:
    for q in P:
        p1 = bisect.bisect_left(a, q[0] - 1)
        p2 = bisect.bisect_right(a, q[1] - 2)
        print((p2 - p1))
else:
    for q in P:
        print((0))

# Optimized solution
import sys

N, Q = list(map(int, input().split()))
S = sys.stdin.readline()
P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

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

for q in P:
    print((a[q[1] - 1] - a[q[0] - 1]))
# Original solution
# C - GeT AC
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import sys
n, q = list(map(int, sys.stdin.readline().split()))

s = sys.stdin.readline()

separators = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

# n = 8
# q = 3
# s = 'ACACTACG'
# separators = [[3, 7],[2, 3],[1, 8]]

# cnt = [0] * n


for i in range(0, len(separators)):
    print((s[separators[i][0]-1:separators[i][1]].count("AC")))


# Optimized solution
# C - GeT AC
# https://abc122.contest.atcoder.jp/tasks/abc122_c

"""
累積和を用いて実装しないと時間が足りない
"""

import sys
n, q = list(map(int, sys.stdin.readline().split()))
s = list(sys.stdin.readline())

cnt = [0] * (len(s)+1)

"""
ACを数えるために受けた文字列ｓを展開して数えていく
"""

for i in range(1, len(s)):
    """
    s = ACACTACG
    cnt = [0,0,1,1,2,2,2,3,3]
    i == 1, 2, 3……len(s)
    
    i == 1
    s[i] == C s[i-1] == A
    ここで代入されるべきなのはcntのindex2番である　
        なぜならば、cntは最初に0を代入するので、s[i]の位置に当たるのはcnt[i]+1であるため
    """

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


r_and_l = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

for e in r_and_l:
    num = e[0]
    print((cnt[e[1]] - cnt[num] ))
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ans = []
    carray = [0] * N
    for i in range(1,N):
        if(S[i-1:i+1] == 'AC'):
            carray[i] = carray[i-1]+1 
            # carray[i:] = map(lambda x:x+1, carray[i:])
        else:
            carray[i] = carray[i-1]
    # print(carray)
    for i in range(Q):
        # print(carray[l[i]-1:r[i]])
        t = carray[r[i]-1] - carray[l[i]-1]
        ans.append(t)

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


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ac = [0]*N
    for i in range(1,N):
        if(S[i-1:i+1] == 'AC'):
            ac[i] = ac[i-1]+1
        else:
            ac[i] = ac[i-1]

    ans = [0]*Q
    for i in range(Q):
        ans[i] = ac[r[i]-1] - ac[l[i]-1]

    for i in ans:
        print(i)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()
# Original solution
import itertools
N,Q = [int(i) for i in input().split()]
S = list(input())

li = [0]*N
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        li[i+1] = 1
ans = list(itertools.accumulate(li))
k = []
for j in range(Q):
    a,b = [int(i) for i in input().split()]
    k.append(ans[b-1]-ans[a-1])

[print(i) for i in k]


# Optimized solution
N,Q = [int(zz) for zz in input().split()]
S = input()

li = [0]*N
Aflag = 0
AC = 0
for i in range(N):
    if S[i] == 'A':
        Aflag = 1
    elif S[i] == 'C' and Aflag:
        AC += 1
        Aflag = 0
    else:
        Aflag = 0
    li[i] = AC

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

[print(i) for i in ans]
# Original solution
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
for i in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print((S[n1-1:n2].count("AC")))

# Optimized solution
from sys import stdin
N,Q=[int(x) for x in stdin.readline().rstrip().split()]
S=(stdin.readline().rstrip())
acc=[0]*N
cnt=0
flag=0
for index,i in enumerate(list(S)):
    if i == "C" and flag == 1:
        cnt+=1
        flag=0
    if i != "C":
        flag=0
    if i == "A":
        flag=1
    acc[index]=cnt
for j in range(Q):
    n1,n2=[int(x) for x in stdin.readline().rstrip().split()]
    print((acc[n2-1]-acc[n1-1]))
# Original solution
from sys import stdin

n, q = list(map(int, stdin.readline().split()))
s = stdin.readline().strip()
count = 0
for i in range(q):
    l, r = list(map(int, stdin.readline().split()))
    for j in range(l - 1, r - 1):
        if s[j] + s[j + 1] == 'AC':
            count += 1

    print(count)
    count = 0


# Optimized solution
from sys import stdin

n, q = list(map(int, stdin.readline().split()))
s = stdin.readline().strip()
counts = [0 for i in range(n)]
count = 0
for i in range(1, n):
    if s[i-1:i+1] == 'AC':
        count += 1
    counts[i] = count

for i in range(q):
    l, r = list(map(int, stdin.readline().split()))
    print((counts[r-1] - counts[l-1]))
# Original solution
N, Q = list(map(int, input().split(" ")))
S = input().strip()

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

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

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

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

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


# Optimized solution
N, Q = list(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 = list(map(int, input().split()))
    ans[i] = check[r] - check[l]

for i in range(Q):
    print((ans[i]))
# Original solution
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

n,q = read_int()
S = read_str()
lr = [read_int() for _ in range(q)]


def solve():
    for i in range(q):
        l,r = lr[i]
        res = 0
        for j in range(l,r):
            # print(S[j-1:j +1])
            if S[j - 1: j + 1] == 'AC':
                res += 1
        print(res)


if __name__ == "__main__":
    solve()

# Optimized solution
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

n,q = read_int()
S = read_str()
lr = [read_int() for _ in range(q)]

dp = [0 for i in range(n+1)]
def solve():
    for i in range(1, n):
        dp[i+1] = dp[i]
        if S[i - 1:i + 1] == 'AC':
            dp[i +1] += 1

    for i in range(q):
        l,r = lr[i]
        print((dp[r]-dp[l]))

        
if __name__ == "__main__":
    solve()
# Original solution
import sys
input = sys.stdin.readline
def print_ans(N, Q, S, arr):
    """Test Case
    >>> print_ans(8, 3, "ACACTACG", [[3, 7], [2, 3], [1, 8]])
    2
    0
    3
    """
    ans_list = [S[ar[0]-1:ar[1]].count("AC") for ar in arr]
    for ans in ans_list:
        print(ans)

if __name__ == '__main__':
    N, Q = list(map(int, input().rstrip().split()))
    S = input().rstrip()
    arr = [list(map(int, input().rstrip().split())) for _ in range(Q)]
    print_ans(N, Q, S, arr)


# Optimized solution
import sys
input = sys.stdin.readline
def print_ans(N, Q, S, arr):
    """Test Case
    >>> print_ans(8, 3, "ACACTACG", [[3, 7], [2, 3], [1, 8]])
    2
    0
    3
    """
    t = [0] * (N+1)
    for i in range(N):
        t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
    for ar in arr:
        print((t[ar[1] - 1] - t[ar[0] - 1] ))

if __name__ == '__main__':
    N, Q = list(map(int, input().rstrip().split()))
    S = input().rstrip()
    arr = [list(map(int, input().rstrip().split())) for _ in range(Q)]
    print_ans(N, Q, S, arr)
# Original solution
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
idx = [i for i in range(N - 1) if S[i:i+2] == 'AC']

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print((sum([i >= l - 1 and i <= r - 2 for i in idx])))


# Optimized solution
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
m = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        m[i] = m[i-1] + 1
    else:
        m[i] = m[i-1]

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print((m[r - 1] - m[l - 1]))
# Original solution
from sys import stdin

sN, sQ = stdin.readline().split()
N, Q = int(sN), int(sQ)
# print(N,Q)
S = stdin.readline().rstrip()
data = [stdin.readline().split() for itr in range(Q)]
# print(data)

for itr in range(Q):
    l = int(data[itr][0]) - 1 
    r = int(data[itr][1])
    s = S[l:r]
    # print(s)
    print((s.count('AC')))

# Optimized solution
from sys import stdin

sN, sQ = stdin.readline().split()
N, Q = int(sN), int(sQ)
# print(N,Q)
S = stdin.readline().rstrip()
data = [stdin.readline().split() for itr in range(Q)]
# print(data)

grid = [None] * N
# print(grid)
count = 0
for num in range(N):
    if num == 0:
        grid[num] = count
        continue
    if S[num] == 'C' and S[num-1] == 'A':
        count += 1
        grid[num] = count
        continue
    grid[num] = count

# print(grid)

for itr in range(Q):
    l = int(data[itr][0]) - 1
    r = int(data[itr][1]) - 1
    # print(grid[r],grid[l])
    print((grid[r]-grid[l]))
# Original solution
N, Q = map(int, input().split())
S = input()
ans = []
for i in range(Q):
    l, r = map(int, input().split())
    T = S[l-1:r]
    ans.append(T.count('AC'))
print(*ans, sep='\n')


# Optimized solution
N, Q = map(int, input().split())
S = input()
T = [0]*(N+1)

for i in range(1, N):
    T[i+1] = T[i] + (1 if S[i-1:i+1]=='AC' else 0)
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(T[r] - T[l])
print(*ans, sep='\n')
# Original solution
def get_ac(n,q,s,l,r):
    pos = []

    for j in range(0,n-1):
        if s[j] == 'A' and s[j+1] == 'C':
            pos.append(j+1)

    p_len = len(pos)
    for i in range(q):
        left = l[i]
        right = r[i]
        count = 0
        for j in range(p_len):
            if left <= pos[j] and pos[j]+1 <= right:
                count += 1
        else:
            print(count)

if __name__ == '__main__':

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

    l = [0]*q
    r = [0]*q

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

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)

# Optimized solution
def get_ac(n,q,s,l,r):
    pos = [0]*n

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

    for i in range(q):
        left = l[i]
        right = r[i]
        count = pos[right - 1] - pos[left - 1]

        print(count)

if __name__ == '__main__':

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

    l = [0]*q
    r = [0]*q

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

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)
# Original solution
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

for i in range(Q):
  L = [int(i) for i in input().split()]
  s = S[L[0]-1:L[1]]

  cnt = 0
  for i in range(0,len(s)):
    if s[i]=='A':
      if i+1!=len(s) and s[i+1]=='C':
        cnt+=1
  print(cnt)


# Optimized solution
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

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

for i in range(Q):
  L = [int(i) for i in input().split()]
  print((num[L[1]]-num[L[0]]))
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    dp = [[None for j in range(N)] for i in range(N)]
    for i in range(0, N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            dp[i][i+1] = 1
        else:
            dp[i][i+1] = 0
    def count(li, ri):
        assert li >= 0 and ri >= 0, "li or ri < 0"
        if dp[li][ri] is not None:
            return dp[li][ri]
        else:
            c = count(li, ri-1) + count(ri-1, ri)
            dp[li][ri] = c
            return c
    for q in range(Q):
        print((count(l[q] - 1, r[q] - 1)))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    c = [0 for i in range(N+1)]
    for i in range(N):
        c[i+1] = c[i] + (1 if S[i:i+2] == "AC" else 0)
    for q in range(Q):
        print((c[r[q]-1] - c[l[q] - 1]))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, Q, S, l, r)

if __name__ == '__main__':
    main()
# Original solution
import sys
from itertools import accumulate


def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input().strip()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    hoges = [0] + [1 if s[i : i + 2] == "AC" else 0 for i in range(n - 1)]
    hoges = list(accumulate(hoges))
    for (l, r) in qs:
        print((hoges[r - 1] - hoges[l - 1]))


if __name__ == "__main__":
    main()


# Optimized solution
# -*- coding: utf-8 -*-
#!/usr/bin/env python3

import sys
from itertools import accumulate


def main():
    input = sys.stdin.readline
    n, q = [int(i) for i in input().split()]
    s = input().strip()
    qs = [[int(i) for i in input().split()] for _ in range(q)]
    hoges = [0] + [1 if s[i : i + 2] == "AC" else 0 for i in range(n - 1)]
    hoges = list(accumulate(hoges))
    for (l, r) in qs:
        print((hoges[r - 1] - hoges[l - 1]))


if __name__ == "__main__":
    main()
# Original solution
N,Q = list(map(int, input().split()))
s = input()

import re
pos = [m.end() for m in re.finditer(r'AC', s)]

def cnt(at):
    ret=0
    for p in pos:
        if p>at:
            break
        ret+=1
    return ret

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

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


# Optimized solution
import re
import itertools

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

pos = [m.end() for m in re.finditer(r'AC', s)]

dp = [0] * (N+1)
for p in pos:
    dp[p] = 1
dp = list(itertools.accumulate(dp))

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

print(*ans, sep='\n')
# Original solution
import sys

n, q = list(map(int, sys.stdin.readline().split()))
s = sys.stdin.readline()

mlist = [0] * q
for i in range(q):
    mlist[i] = list([int(i) for i in sys.stdin.readline().split()])

elist = [0] * (n+1)

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

for i in range(q):
    l, r = mlist[i]
    print((elist[r] - elist[l]))


# Optimized solution
import sys

n, q = list(map(int, sys.stdin.readline().split()))
s = sys.stdin.readline()

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

for i in range(q):
    l, r = list(map(int, sys.stdin.readline().split()))
    print((elist[r] - elist[l]))
# Original solution
import re
n,q=map(int,input().split())
s=input()
ans=[0]*q
for i in range(q):
    l,r=map(int,input().split())
    ans[i]=len(re.findall('(AC)',s[l-1:r]))
print(*ans,sep='\n')


# Optimized solution
n,q=map(int,input().split())
s=input()
l=[0]*(len(s)+1)
for i in range(1,len(s)):
    l[i+1]=l[i]
    if s[i-1]=='A' and s[i]=='C':
        l[i+1]+=1
ans=[0]*q
for i in range(q):
    a,b=map(int,input().split())
    ans[i]=l[b]-l[a]
print(*ans,sep='\n')
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    n, q = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    lr = [list(map(int, input().rstrip('\n').split())) for _ in range(q)]
    l = [0] * n
    cnt = 0
    for i in range(1, n):
        if s[i] == "C" and s[i-1] == "A":
            cnt += 1
        l[i] = cnt
    for ln, rn in lr:
        print((l[rn-1] - l[ln-1]))


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    n, q = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    ls = [0] * n
    cnt = 0
    for i in range(1, n):
        if s[i] == "C" and s[i-1] == "A":
            cnt += 1
        ls[i] = cnt
    for i in range(q):
        l, r = list(map(int, input().rstrip('\n').split()))
        print((ls[r-1] - ls[l-1]))


if __name__ == '__main__':
    slove()
# Original solution
import sys
sy = sys.stdin.readlines()
_,Q = list(map(int, sy[0].split()))
S = sy[1]

for i in range(Q):
  l, r = list(map(int, sy[2+i].split()))
  s = S[l-1:r]
  print((s.count('AC')))


# Optimized solution
import sys
sy = sys.stdin.readlines()
N,Q = list(map(int, sy[0].split()))
S = sy[1]
ACindex = [0 for _ in range(N+1)]
count = 0
for n in range(1, N):
  if S[n-1]=="A" and S[n]=="C":
    count += 1
  ACindex[n+1] = count

for i in range(Q):
  l, r = list(map(int, sy[2+i].split()))
  print((ACindex[r]-ACindex[l]))
# Original solution
print(("".join([ [ "{0}\n".format(NQ_S[1][0][LR[0]-1:LR[1]].count('AC')) for LR in [list(map(int, input().split())) for i in range(NQ_S[0][1])] ] for NQ_S in [[[int(x) for x in input().split()],[str(x) for x in input().split()]]] ][0])[:-1]))

# Optimized solution
print(("".join([ [ [ "{0}\n".format(NQ_S[2][LR[1]-1]-NQ_S[2][LR[0]-1]) for LR in  [list(map(int, input().split())) for i in range(NQ_S[0][1])]] for x in [[NQ_S[2].append(NQ_S[2][i-1]+1) if NQ_S[1][0][i-1]=='A' and NQ_S[1][0][i]=='C' else NQ_S[2].append(NQ_S[2][i-1]) for i in range(1,len(NQ_S[1][0]))]]] for NQ_S in [[[int(x) for x in input().split()],[str(x) for x in input().split()],[0]]] ][0][0])[:-1]))
# Original solution
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = [0] * N
    pre = 0
    for i, c1, c2 in zip(list(range(1, N)), S[:], S[1:]):
        AC[i] += pre
        if c1 == "A" and c2 == "C":
            AC[i] += 1
        pre = AC[i]
    for l, r in lr:
        print((AC[r] - AC[l]))
    return


main()


# Optimized solution
from sys import stdin


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    S = lines[1]
    lr = [[int(j) - 1 for j in i.split()] for i in lines[2:]]
    AC = [0] * N
    pre = 0
    for i, c1, c2 in zip(list(range(1, N)), S[:], S[1:]):
        if c1 == "A" and c2 == "C":
            pre += 1
        AC[i] = pre
    for l, r in lr:
        print((AC[r] - AC[l]))
    return


main()