

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
raw.chars.length.times do|index|
  if index == (raw.length-1)
    next
  end
  if raw[index] == "A" && raw[index+1] == "C"
    answer_nums << index
  end
end
q.times do|ss|
  todayq = questions[ss]
  putnum = 0
  answer_nums.each {|po|
  if po < (todayq[0]-1)
    next
  end
  if (todayq[0]-1) <= po && (todayq[1]-2 >= po)
    putnum += 1
  end
  if (todayq[1]-2 < po)
    break
  end
  }
  puts putnum.to_s
end