def howmany x,y,raw
  return raw[(x-1)..(y-1)].scan('AC').size.to_s
end
datas = gets.split(" ").map{|n|n.to_i}
n = datas[0]
q = datas[1]

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

#全パターン作成＝＞取り出し
items = {}
(1..n).each do|num|
  (num..n).each do|num2|
    items[(num.to_s + num2.to_s)] = howmany(num,num2,raw)
  end
end

q.times do|n|
  puts items[questions[n].join("")]
end