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

for i in 0..(str.size)
  map.push(i+1) if str[i] == 'A' && str[i+1] == 'C'
end

q.times do |line|
  f,t = gets.chomp.split.map(&:to_i)
  cnt = 0
  map.each do |i|
    cnt += 1 if f <= i && i < t
  end
  puts cnt
end