line = gets.split(' ').map(&:to_i)
n = line[0]
q = line[1]

nline = gets.split('')
jline = Array.new(n-1)
qline = Array.new(q)
for i in 0..n-2 do
  if nline[i] == "A" && nline[i+1] == "C"
    jline[i] = 1
  else
    jline[i] = 0
  end
end

q.times do |i|
  line2 = gets.split(' ').map(&:to_i)
  l = line2[0]
  r = line2[1]
  qline[i] = jline[l-1..r-2].count(1)
end
puts qline
