STDIN.gets
s = STDIN.gets
acm = Array.new(s.length, 0)

flg = false
i = 0
s.chars do |c|
  if c == 'A'
    flg = true
  else
    if c == 'C' && flg
      acm[i-1] = 1
    end
    flg = false
  end
  i+=1
end

lines = STDIN.readlines
lines.each do |line|
  st, e = line.split(' ')
  puts acm[st.to_i-1..e.to_i-2].inject(:+)
end