n, q = gets.split.map(&:to_i)
s = gets.chomp
l = []
r = []
judg=Array.new(q,"")
for i in 0...q do
  l[i], r[i] = gets.split.map(&:to_i)
  l[i].upto(r[i]) do |j|
    judg[i] = judg[i] + s[j-1]
  end
end
for i in 0...q do
  puts judg[i].scan("AC").length
end