n, q = gets.split.map(&:to_i)
s = gets.chomp

at = [0]
c = 0
for i in (0..s.length - 2)
  at[i+1] = s[i,2] == 'AC' ? c += 1 : c
end

q.times do
  l, r = gets.split.map(&:to_i)
  puts at[r-1] - at[l-1]
 end