n, q = gets.chop.split.map(&:to_i)
s = gets.chop
lr = []
q.times do
  lr << gets.chop.split.map(&:to_i)
end

cum_sum = []
cum_sum[0] = 0

n.times do |num|
  unless num == 0 then
    cum_sum[num] = s[0, num+1].scan('AC').length
  end
end


for elm in lr do
  puts cum_sum[elm[1]-1]-cum_sum[elm[0]-1]
end
