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

# In[8]:


N,Q = map(int, input().split())
S = input()
mylist = []
for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        mylist.append(i)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = [1 for x in mylist if l-1<= x and x+1<=r-1]
    print(sum(ans))


# In[ ]:






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

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


# In[ ]:

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

# In[8]:


N,Q = map(int, input().split())
S = input()
mylist = []
for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        mylist.append(i)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = [1 for x in mylist if l-1<= x and x+1<=r-1]
    print(sum(ans))


# In[ ]:






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

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


# In[ ]:

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

# In[22]:


N,Q = map(int, input().split())
S = str(input())
#data = []
#for i in range(Q):
#    data.append(list(map(int, input().split())))
data = []
for i in range(Q):
    data= list(map(int, input().split()))
    print(S[data[0]-1:data[1]].count("AC"))


# In[23]:


#for j in range(Q):
#    print(S[data[j][0]-1:data[j][1]].count("AC"))


# In[ ]:






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

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


# In[ ]:

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

# In[3]:


N,Q = map(int, input().split())
S = str(input())
data = []
for i in range(Q):
    data.append(list(map(int, input().split())))


# In[17]:


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


# In[ ]:






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

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


# In[ ]:

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

# In[3]:


N,Q = map(int, input().split())
S = str(input())
data = []
for i in range(Q):
    data.append(list(map(int, input().split())))


# In[17]:


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


# In[ ]:






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

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


# In[ ]:

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

# In[3]:


N,Q = map(int, input().split())
S = str(input())
data = []
for i in range(Q):
    data.append(list(map(int, input().split())))


# In[17]:


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


# In[ ]:






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

# In[15]:


N,Q = map(int, input().split())
S = list(input())
mylist = [0]
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == "A" and S[i] == "C":
        cnt += 1
    mylist.append(cnt)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = mylist[r-1] - mylist[l-1]
    print(ans)


# In[ ]: