# import bisect

# from collections import Counter, deque

# import copy

# from fractions import gcd

# from functools import reduce

from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

# import math

# import numpy as np

# import sys

# sys.setrecursionlimit(10**9)



def resolve():

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

    S=str(eval(input()))



    L, R = [0] * Q, [0] * Q

    for i in range(Q):

        L[i], R[i] = list(map(int, input().split()))

        L[i], R[i] = L[i]-1, R[i]-1



    A=[0]*N

    for i in range(N-1):

        if S[i:i+2]=='AC':

            A[i]=1



    B = [0] + A

    B = list(accumulate(B))  # 累積和を格納したリスト作成



    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り

    for j in range(Q):

        ans=B[R[j]]-B[L[j]]

        print(ans)







resolve()
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

# import math

# import numpy as np  # Pythonのみ！

# from operator import xor

# import re

# from scipy.sparse.csgraph import connected_components  # Pythonのみ！

# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/

# from scipy.sparse import csr_matrix

# import string

import sys

sys.setrecursionlimit(10 ** 5 + 10)

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



def resolve():



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

    S=list(eval(input()))

    res=[0]*N



    temp=False

    for i in range(N):

        if S[i]=='A':

            temp=True

        elif temp==True and S[i]=='C':

            res[i-1]=1

            temp=False

        else: temp=False





    B = [0] + res

    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]

    B = list(accumulate(B))



    for i in range(Q):

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

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







resolve()
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    groupby,
    product,
)

# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)
def resolve():
    N, Q = list(map(int, input().split()))
    S = str(eval(input()))
    L, R = [0] * Q, [0] * Q
    for i in range(Q):
        L[i], R[i] = list(map(int, input().split()))
        L[i], R[i] = L[i] - 1, R[i] - 1
    A = [0] * N
    for i in range(N - 1):
        if S[i : i + 2] == "AC":
            A[i] = 1
    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成
    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    for j in range(Q):
        ans = B[R[j]] - B[L[j]]
        print(ans)


resolve()

from itertools import (
    accumulate,
    permutations,
    combinations,
    combinations_with_replacement,
    groupby,
    product,
)

# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10**5 + 10)


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


def resolve():
    N, Q = list(map(int, input().split()))
    S = list(eval(input()))
    res = [0] * N
    temp = False
    for i in range(N):
        if S[i] == "A":
            temp = True
        elif temp == True and S[i] == "C":
            res[i - 1] = 1
            temp = False
        else:
            temp = False
    B = [0] + res
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    B = list(accumulate(B))
    for i in range(Q):
        l, r = list(map(int, input().split()))
        print((B[r - 1] - B[l - 1]))


resolve()

-# import bisect -# from collections import Counter, deque -# import copy -# from fractions import gcd -# from functools import reduce -# import numpy as np -# import sys -# sys.setrecursionlimit(10**9) +# import numpy as np  # Pythonのみ！ +# from operator import xor +# import re +# from scipy.sparse.csgraph import connected_components  # Pythonのみ！ +# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/ +# from scipy.sparse import csr_matrix +# import string +import sys + +sys.setrecursionlimit(10**5 + 10) + + +def input(): +    return sys.stdin.readline().strip() + + -    S = str(eval(input())) -    L, R = [0] * Q, [0] * Q +    S = list(eval(input())) +    res = [0] * N +    temp = False +    for i in range(N): +        if S[i] == "A": +            temp = True +        elif temp == True and S[i] == "C": +            res[i - 1] = 1 +            temp = False +        else: +            temp = False +    B = [0] + res +    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l] +    B = list(accumulate(B)) -        L[i], R[i] = list(map(int, input().split())) -        L[i], R[i] = L[i] - 1, R[i] - 1 -    A = [0] * N -    for i in range(N - 1): -        if S[i : i + 2] == "AC": -            A[i] = 1 -    B = [0] + A -    B = list(accumulate(B))  # 累積和を格納したリスト作成 -    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り -    for j in range(Q): -        ans = B[R[j]] - B[L[j]] -        print(ans) +        l, r = list(map(int, input().split())) +        print((B[r - 1] - B[l - 1]))