N, Q = gets.split.map(&:to_i)
S = gets.chomp

acc = Array.new(N, 0)


(N-1).times do |i|
  
   ( S[i] == ?A && S[i+1] == ?C ) ? acc[i+1] = acc[i] + 1 : acc[i+1] = acc[i]
  
end

# p acc


Q.times do |i|
  
  l, r = gets.split.map(&:to_i)
  l -= 1
  r -= 1
  
  puts acc[r] - acc[l]
  
end
