datas = gets.split(" ").map{|n|n.to_i}
n = datas[0]
q = datas[1]

raw = gets
questions = []
q.times do
  questions << gets.split(" ").map{|n|n.to_i}
end

q.times do|ss|
  todayq = questions[ss]
  sample = raw[(todayq[0]-1)..(todayq[1]-1)]
  puts (sample.scan('AC').size.to_s)
end