n, q = gets.split.map(&:to_i)
s = gets.chomp
l, r = Array.new(q) { gets.split.map(&:to_i) }.transpose
cum = [0]
count = 0

n.times do |i|
  cum[i + 1] ||= count

  if s[i] == 'A' && s[i + 1] == 'C'
    count += 1
    cum[i + 2] = count
  end
end

l.zip(r).each { |l, r| puts cum[r] - cum[l] }