n, q = gets.split.map(&:to_i)
s = gets.chomp
hist = Array.new(n, 0)
count = 0
for i in 0...(n - 1) do
  if s[i] == "A" && s[i + 1] == "C"
    count += 1
  end
  hist[i + 1] = count
end
q.times do
  l, r = gets.split.map(&:to_i)
  puts hist[r - 1] - hist[l - 1]
end
