q = gets.split[1].to_i
s = gets
 
q.times do
  counter = 0
  buf = ""
  start = 0
  l, r = gets.split.map(&:to_i)
  while(idx = s[l-1..r-1].index("AC", start)) do
    counter += 1
    start = idx+2
  end
  puts counter
end