q = gets.split[1].to_i
s = gets

start = 0
idx = 0
idxs = []
while(idx = s.index("AC", start)) do
  counter += 1
  start = idx+2
  idxs.append idx
end
q.times do
  l, r = gets.split.map(&:to_i)
  counter = 0
  idxs.each do |i|
    counter += 1 if l <= i && i+1 <= r
  end
  puts i
end