N, Q = gets.split.map &:to_i
S = gets.chomp

cusum = [sum = 0] + (0...N).map{|i|
  if i != 0 && S[i-1] == ?A && S[i] == ?C
    sum += 1
  end
  sum
}
# p cusum
$<.map{|s|
  l, r = s.split.map &:to_i
  p cusum[r] - cusum[l]
}
