def positions(s, subs)
  res = []
  i = 0
  while true
    tmp = s.index(subs, i)
    if tmp
      res.push(tmp)
      i = tmp + subs.size
    else
      break
    end
  end
  return res
end

n, q = gets.split.map(&:to_i)
s = gets.chomp
spans = q.times.map { gets.split.map(&:to_i) }
poss = positions(s, "AC")
rsums = []

i = s.size - 1
sum = 0
poss.reverse_each do |pos|
  i.downto(pos+1).each do |j|
    rsums[j] = sum
  end
  sum += 1
  rsums[pos] = sum
  i = pos - 1
end
rsums[s.size] = 0

spans.each do |l, r|
  puts rsums[l-1] - rsums[r-1]
end
