N, Q = gets.chomp.split(" ").map(&:to_i)
S = gets.chomp
LR = []
Q.times{
  LR << gets.chomp.split(" ").map(&:to_i)
}

AC = []
s = 0
while true do
  wk = S.index('AC', s)
  break if wk.nil?
  AC << wk
  s += 2
end

LR.each{|l, r|
  puts AC.count{|a| l-1 <= a && a <= r-2}
}
