n, q = gets.split.map(&:to_i)
s = gets.chomp
lr =
  q.times.map do |i|
    gets.split.map(&:to_i)
  end

idxs=[]
i=0
while i<n-1 do
  if s[i]=='A' && s[i+1]=='C'
    idxs<<i
  end
  i+=1
end
#puts idxs.to_s
q.times.map do |i|
  l = lr[i][0]
  r = lr[i][1]
  i1 = idxs.bsearch_index{|x|x>=l-1}
  i2 = idxs.bsearch_index{|x|x>=r-1}
  #puts "i:#{i1},#{i2}"
  if i1.nil?
    puts 0
    next
  end
  if i2.nil?
    i2 = idxs.size
  end
  puts (i2-1)-i1+1
end