Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n, q, s, ll, lr):
    aas = []
    a_append = aas.append
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            a_append(i)
    
    rsw = [0]
    a = 0
    rs_append = rsw.append
    for i in range(1,n+1):
        if i in aas:
            a += 1
        rs_append(a)

    ans = 0
    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    l_append = ll.append
    r_append = lr.append
    for i in range(q):
        l, r = list(map(int, input().split()))
        l_append(l)
        r_append(r)

    sol(n,q,s,ll,lr)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

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

Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n, q, s, ll, lr):
    aas = []
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            aas.append(i)
    
    rsw = [0]
    a = 0
    for i in range(1,n+1):
        if i in aas:
            a += 1
        rsw.append(a)

    ans = 0
    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        ll.append(l)
        lr.append(r)
    sol(n,q,s,ll,lr)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

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

Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n, q, s, ll, lr):
    aas = []
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            aas.append(i)
    rsw = [0]
    a = 0
    
    for i in range(1,n+1):
        if i in aas:
            a += 1
        rsw.append(a)

    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        ll.append(l)
        lr.append(r)
    sol(n,q,s,ll,lr)

main()


Fixed submission:
import sys
input = sys.stdin.readline

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

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

Buggy python submission (verdict: Time Limit Exceeded):
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n, q, s, ll, lr):
    aas = []
    for i in range(1,n):
        if s[i-1]=="A" and s[i]=="C":
            aas.append(i)
    rsw = [0]
    a = 0

    for i in range(1,n+1):
        if i in aas:
            a += 1
        rsw.append(a)
    for i in range(q):
        ans = rsw[lr[i]-1]-rsw[ll[i]-1]
        print(ans)

def main():
    import sys
    input = sys.stdin.readline 
    l = list(map(int, input().split()))
    n = l[0]
    q = l[1]
    s = input()
    ll = []
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        ll.append(l)
        lr.append(r)
    sol(n,q,s,ll,lr)

main()


Fixed submission:
import sys
input = sys.stdin.readline

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

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

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