n, q = gets.chomp.split(' ').map {|v| v.to_i}
s = gets.chomp

sum = Array.new(1 + s.length, 0)
for i in 1..s.length do
  v = sum[i - 1]
  if s[i - 1] == 'A' and s[i] == 'C'
    v += 1
  end
  sum[i] = v
end

q.times do |j|
  l, r = gets.chomp.split(' ').map {|v| v.to_i}
  v = sum[r - 1] - sum[l - 1]
  puts v
end
