Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[78]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=list()
import re
i = 0
pAC=re.compile("AC")
while i >= 0:
    m = pAC.search(S, i)
    if m:
        l.append(m.start()+1)
        #l.append(m.end())
        i = m.start() + 1
    else:
        break
#print(l)
for i in range(Q):
    print(sum(x >= lr[i][0] and x<lr[i][1] for x in l))


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[4]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        l[i+1]=1+l[i]
    else:
        l[i+1]=l[i]
for i in range(Q):
    print(l[lr[i][1]-1]-l[lr[i][0]-1])


# In[ ]:

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[63]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
for i in range(Q):
    #t=S[lr[i][0]-1:lr[i][1]]
    #t=[S for j in range(lr[i][0],lr[i][1])]
    #print(t)
    for j in range(lr[i][0]-1,lr[i][1]-1):
        if S[j]=='A' and S[j+1]=='C':
            ct+=1
    print(ct)
    ct=0
   # if i==Q:
    #    break


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[4]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        l[i+1]=1+l[i]
    else:
        l[i+1]=l[i]
for i in range(Q):
    print(l[lr[i][1]-1]-l[lr[i][0]-1])


# In[ ]:

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[46]:


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

for i in range(Q):
    t=S[lr[i][0]-1:lr[i][1]]
    #t=[S for j in range(lr[i][0],lr[i][1])]
    #print(t)
    print(t.count('AC'))
    if i==Q:
        break


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[4]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        l[i+1]=1+l[i]
    else:
        l[i+1]=l[i]
for i in range(Q):
    print(l[lr[i][1]-1]-l[lr[i][0]-1])


# In[ ]:

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[35]:


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

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

for i in range(Q):
    t=S[lr[i][0]-1:lr[i][1]]
   # t=[S for j in range(lr[i][0],lr[i][1])]
    #print(t)
    print(t.count('AC'))
    if i==Q:
        break


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[4]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        l[i+1]=1+l[i]
    else:
        l[i+1]=l[i]
for i in range(Q):
    print(l[lr[i][1]-1]-l[lr[i][0]-1])


# In[ ]:

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[32]:


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

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

for i in range(Q):
    t=S[lr[i][0]-1:lr[i][1]]
   # t=[S for j in range(lr[i][0],lr[i][1])]
   # print(t)
    print(t.count('AC'))


# In[ ]:






Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[4]:


N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for l in range(Q)]
ct=0
l=[0]*(N+1)
for i in range(0,len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        l[i+1]=1+l[i]
    else:
        l[i+1]=l[i]
for i in range(Q):
    print(l[lr[i][1]-1]-l[lr[i][0]-1])


# In[ ]: