def ac_count(s,l,r)
  cnt = 0;
  c = l-1
  while c < r-1
    if s[c] == 'A'
      if s[c+1] == 'C'
        cnt += 1
      end
      c += 2
    else
      c += 1
    end
  end
  cnt
end

(n, q) = readline.chop.split(' ').map{|x| x.to_i}
s = readline.chop
q.to_i.times do
  (l,r) = readline.chop.split(' ').map{|x| x.to_i}
  puts ac_count(s,l,r)
end