N,Q = gets.split.map(&:to_i)
S = gets.chomp
lr = Q.times.map { gets.chomp.split.map(&:to_i) }

A = Array.new
(0...N).each do |i|
  c = S[(0..i)].scan('AC').size
  A << c
end

Q.times do |j|
  ans = A[lr[j][1]-1] - A[lr[j][0]-1]
  puts ans
end