n,q = gets.split().map(&:to_i)
s = gets.chomp

counts = []
q.times do |i|
  l,r = gets.split().map(&:to_i)
  str = s[l-1..r-1]

  count = 0
  a = false
  str.chars do |c|
    a = true if c =="A"
    if a && c == "C" then
      count = count + 1
      a = false
    end
  end
  counts << count
end

counts.each do |e|
  p e
end