str = gets.split
N,Q = str[0].to_i, str[1].to_i
S = gets.chomp

B = []
B[0] = 0

for x in 0...N-1
  if S[x] == "A" && S[x+1] == "C"
    B[x+1] = B[x] + 1 
  else
    B[x+1] = B[x]
  end
end

for x in 1..Q
  str = gets.split
  l,r = str[0].to_i, str[1].to_i
  puts B[r-1] - B[l-1]
end