n, q = read_line.split.map(&.to_i)
s = read_line.chomp
l = Array.new(q,0)
r = Array.new(q,0)
cash = Array.new(q,"")
ans = ""
q.times do |i|
  l[i], r[i] = read_line.split().map(&.to_i)
  l[i].upto(r[i]) do |j|
    cash[i] = cash[i] + s[j-1]
  end
  ans = ans + cash[i].scan("AC").size.to_s + "\n"
end
puts ans