def get_n(s, line)
  l , r = line.split(' ')
  l = l.to_i - 1
  r = r.to_i - 1
  sub_str = s[l..r]
  return sub_str.count('AC').size
end


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