N, Q = gets.split.map(&:to_i)
S = gets.chomp
ls = Array.new(Q)
rs = Array.new(Q)
Q.times do |i|
  ls[i], rs[i] = gets.split.map(&:to_i)
end

sum_array = Array.new(S.length)
sum_array[0] = 0
sum = 0
(S.length - 1).times{|x|
  if S[x..(x+1)] == "AC"
    sum = sum + 1
  end
  sum_array[x+1] = sum
}

Q.times{|x|
  puts sum_array[rs[x]-1] - sum_array[ls[x]-1]
}
