n,q = gets.chomp.split.map(&:to_i)
str = gets.chomp
map = [0]

cnt = 0
(n-1).times do |i|
  cnt += str[i] == 'A' && str[i+1] == 'C' && 1 || 0
  map.push(cnt)
end

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