n, q = gets.split.map(&:to_i)
s = gets.chomp
l = []
r = []
cash=Array.new(q,"")
ans = ""
for i in 0...q do
  l[i], r[i] = gets.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").length.to_s + "\n"
end
puts ans