N, Q = gets.split.map(&:to_i)
str = gets.chomp
# 0文字目まで、1文字目までは自明に0
rui = [0, 0]
ite = 2
str.chars.each_cons(2) do |c1, c2|
  rui[ite] = rui[ite - 1] + ((c1 == 'A' && c2 == 'C') ? 1 : 0)
  ite += 1
end
Q.times do
  s, l = gets.split.map(&:to_i)
  puts rui[l] - rui[s]
end