include Math
require 'tsort'

loop do
	n = gets.to_i
	break if n == 0
	xs, ys, xt, yt = gets.split.map(&:to_i)

	walls = []
	n.times do
		x, y, r = gets.split.map(&:to_i)
		contain_s = ((x - xs) ** 2 + (y - ys) ** 2 < r ** 2)
		contain_t = ((x - xt) ** 2 + (y - yt) ** 2 < r ** 2)
		next if contain_s && contain_t
		if contain_s
			walls << [x, y, r, :s]
		elsif contain_t
			walls << [x, y, r, :t]
		end
	end
	
	if walls.empty?
		puts 0
		next
	end

	class Hash
		include TSort
		alias :tsort_each_node :each_key
		def tsort_each_child(i)
			self[i].each {|j| yield j}
		end
	end

	graph = {}
	(0..walls.size-1).each {|i| graph[i] = []}

	(0..walls.size-1).to_a.permutation(2) do |i, j|
		x1, y1, r1, c1 = walls[i]
		x2, y2, r2, c2 = walls[j]

		case [c1, c2]
		when [:s, :s]
			if r1 < r2 && (x1 - x2) ** 2 + (y1 - y2) ** 2 < (r2 - r1) ** 2
				graph[i] << j
			end
		when [:s, :t]
			if (x1 - x2) ** 2 + (y1 - y2) ** 2 > (r1 + r2) ** 2
				graph[i] << j
			end
		when [:t ,:t]
			if r1 > r2 && (x1 - x2) ** 2 + (y1 - y2) ** 2 < (r1 - r2) ** 2
				graph[i] << j
			end
		else
		end
	end
    
	ts = graph.tsort
	path_len = {}
	ts.each do |i|
		if graph[i].empty?
			path_len[i] = 1
		else
			path_len[i] = graph[i].map{|j| path_len[j]}.max + 1
		end
	end
	p path_len.values.max
end