def get_n(a, line)
  l , r = line.split(' ')
  l = l.to_i - 1
  r = r.to_i - 1
  n = a[r] - a[l]
  return n
end

gets
s = gets.chomp
#acの個数の累積和を計算しておく
a = Array.new
followed_by_a = false
num = 0
s.each_char.each_with_index do |c, i|
  if followed_by_a
    if c == 'C'
      num = num + 1
    end
  end
  if c == 'A'
    followed_by_a = true
  else
    followed_by_a = false
  end
  a << num
end

while(line = gets)
  line = line.chomp
  n = get_n(a, line)
  puts n
end
