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