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]

  counts << "z#{str}z".split("AC").length
end

counts.each do |e|
  p e-1
end