ary = Array.new
while line = $stdin.gets
ary << line.chomp.split
end
kosu=ary[0][0].to_i
ary.delete_at(0)
moji = ary[0][0].split("")
ary.delete_at(0)
matome = Array.new

kosu.times{|t|
if moji[t]=="A" and moji[t+1]=="C" then
    matome.push(t+1)
end
}
ary.each{|k|
a=k[0].to_i
b=k[1].to_i
kotae = 0
matome.each{|item|
  if  a <=item and item<b then
    kotae +=1
  end
    }
puts kotae
}