import bisect
I=lambda:map(int,input().split())
N,Q=I()
S=input()
m=[0]
for i in range(N-1):
    m+=[m[-1]+(1 if S[i:i+2]=='AC' else 0)]
print(m)
for i in range(Q):
    l,r=I()
    print(m[r-1]-m[l-1])