Buggy python submission (verdict: Runtime Error):
import numpy as np

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

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  L_str = L_str + S[i+1]
  L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  R_str = S[N-2-i] + R_str
  R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""



Fixed submission:
import numpy as np

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

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  #L_str = L_str + S[i+1]
  #L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  #R_str = S[N-2-i] + R_str
  #R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)
  #L_str = S[i] + S[i+1]
  #L_cnt[i+1] = L_cnt[i] + (L_str == 'AC')
  #R_str = S[N-2-i] + S[N-1-i]
  #R_cnt[i+1] = R_cnt[i] + (R_str == 'AC')
  L_str = S[i] + S[i+1]
  L_cnt[i+1] = (L_str == 'AC')
  R_str = S[N-2-i] + S[N-1-i]
  R_cnt[i+1] = (R_str == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  #ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  ans = n_whole - (sum(L_cnt[:A[i][0]]) + sum(R_cnt[:N-A[i][1]+1]))
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""



Fixed submission:
import numpy as np

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

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  L_str = L_str + S[i+1]
  L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  R_str = S[N-2-i] + R_str
  R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  #ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  A = list(map(int,input().split()))
  ans = n_whole - (L_cnt[A[0]-1] + R_cnt[N-A[1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""



Fixed submission:
import numpy as np

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

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

L_cnt = np.zeros(N-1)
L_cnt[0] = 0
L_str = S[0]
R_cnt = np.zeros(N-1)
R_cnt[0] = 0
R_str = S[N-1]

for i in range(N-2):
  L_str = L_str + S[i+1]
  L_cnt[i+1] = L_cnt[i] + (L_str[-2:] == 'AC')
  R_str = S[N-2-i] + R_str
  R_cnt[i+1] = R_cnt[i] + (R_str[:2] == 'AC')
  #print(i, L_str)
  #print(i, R_str)

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
for i in range(Q):
  ans = n_whole - (L_cnt[A[i][0]-1] + R_cnt[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""



Fixed submission:
import numpy as np

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

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import numpy as np
import math

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

for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)




Fixed submission:
import numpy as np

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

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""