n, q = gets.chomp.split.map(&:to_i)
s = gets.chomp
count = [0]

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

q.times do
  l, r = gets.chomp.split.map(&:to_i)
  puts(count[r-1] - count[l-1])
end