Buggy python submission (verdict: Time Limit Exceeded):
""" AtCoder """

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

l = []
pos = 0

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

for i in range(Q):
    tmp = l[lr[i][0] - 1:lr[i][1]]
    ans = sum(tmp)
    if tmp[-1] == 1:
        ans -= 1
    print(ans)


Fixed submission:
""" AtCoder """

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

tmp = 0
l = [0]

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

for i in range(Q):
    print(l[lr[i][1]-1] - l[lr[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
""" AtCoder """

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

l = []
pos = 0

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

for i in range(Q):
    tmp = l[lr[i][0] - 1:lr[i][1]]
    ans = sum(tmp)
    if tmp[-1] == 1:
        ans -= 1
    print(ans)


Fixed submission:
""" AtCoder """

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

tmp = 0
l = [0]

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

for i in range(Q):
    print(l[lr[i][1]-1] - l[lr[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
""" AtCoder """

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

l = []
pos = 0

for _ in range(S.count("AC")):
    i = S.index("AC")
    l.append(i + pos + 1)
    pos = pos + i + 2
    S = S[i + 2:]

check = True

for i in range(Q):
    while True:
        if lr[i][0] not in l:
            lr[i][0] += 1
        else:
            break
        if lr[i][0] > lr[i][1]:
            check = False
            break
    while True:
        if (lr[i][1] - 1) not in l:
            lr[i][1] -= 1
        else:
            break
        if lr[i][1] < lr[i][0]:
            check = False
            break
    if check:
        print(l.index(lr[i][1] - 1) - l.index(lr[i][0]) + 1)
    else:
        print(0)
    check = True


Fixed submission:
""" AtCoder """

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

tmp = 0
l = [0]

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

for i in range(Q):
    print(l[lr[i][1]-1] - l[lr[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
""" AtCoder """

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

l = []
pos = 0

for _ in range(S.count("AC")):
    i = S.index("AC")
    l.append(i + pos + 1)
    pos = pos + i + 2
    S = S[i + 2:]

for i in range(Q):
    tmp = []
    tmp.extend(l)
    tmp.append(lr[i][0])
    tmp.append(lr[i][1])
    tmp.sort()
    print(tmp.index(lr[i][1]) - tmp.index(lr[i][0]) - 1)


Fixed submission:
""" AtCoder """

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

tmp = 0
l = [0]

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

for i in range(Q):
    print(l[lr[i][1]-1] - l[lr[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
""" AtCoder """

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

for i in range(Q):
    print(S[lr[i][0] -1:lr[i][1]].count("AC"))



Fixed submission:
""" AtCoder """

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

tmp = 0
l = [0]

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

for i in range(Q):
    print(l[lr[i][1]-1] - l[lr[i][0]-1])