n, q = gets.chomp.split.map(&:to_i)
s = gets.chomp.split("")
for i in 1..q
  l, r = gets.chomp.split.map(&:to_i)
  acou = s.count("A")
  ccou = s.count("C")
  acnt = ccnt = cnt = 0
  id = l - 1
  while id <= r - 2 && acnt < acou && ccnt < ccou
    if s[id] == "A"
      acnt += 1
      if s[id+1] == "C"
        ccnt += 1
        cnt += 1
        id += 2
      else
        id += 1
      end
    elsif s[id] == "C"
      ccnt += 1
      id += 1
    else
      id += 1
    end
  end
  puts cnt
end