n, q = gets.strip.split.map(&:to_i)
s = gets.strip
qs = q.times.map { gets.strip.split.map(&:to_i) }

len = s.chars.count()
counts = [0]
current = 0

(1..(len - 1)).each do |i|
  if s[i - 1] == 'A' && s[i] == 'C'
    current += 1
  end

  counts << current
end

qs.each do |l, r|
  puts(counts[r - 1] - counts[l - 1])
  puts(s[(l - 1)..(r - 1)])
end
