_,q=gets.chomp.split(' ').map(&:to_i)
s=gets.chomp
arry=[]
q.times { arry << gets.chomp.split(' ').map(&:to_i) }
a=[0]
s.each_char.with_index(1) do |c,idx|
  a[idx] = a[idx-1]+(c=="A"&&s[idx]=="C" ? 1 : 0)
end

arry.each do |b|
  print("#{(a[(b[0]-1)..(b[1]-1)].last)-(a[(b[0]-1)..(b[1]-1)].first)}\n")
end