require 'matrix'
include Math

EPS = 0.000001

loop do
	n = gets.to_i
	break if n == 0

	anchors = (1..n).map{gets.split.map &:to_f}
	max = -Float::INFINITY
	
	anchors.each do |x, y, z|
		if anchors.all?{|a, b, r| (x-a)**2 + (y-b)**2 + z**2 <= r**2 + EPS}
			max = z if z > max
		end
	end
	
	anchors.combination(2) do |u, v|
		u, v = v, u if u[-1] < v[-1]
		(a1, b1, r1), (a2, b2, r2) = u, v
		d = Math.hypot(a1-a2, b1-b2)
		l = (d + (r1**2 - r2**2) / d) / 2
		q = l / d
		next if q < 0 || 1 < q
		x = (1-q)*a1 + q*a2		
		y = (1-q)*b1 + q*b2
		z = sqrt(r1**2 - (x-a1)**2 - (y-b1)**2)
		if anchors.all?{|a, b, r| (x-a)**2 + (y-b)**2 + z**2 <= r**2 + EPS}
			max = z if z > max
		end
	end
	
	anchors.combination(3) do |u, v, w|
		(a1, b1, r1), (a2, b2, r2), (a3, b3, r3) = u, v, w
	
		mat = Matrix[
			[2*(a1-a2), 2*(b1-b2)],
			[2*(a2-a3), 2*(b2-b3)]
			]
		next if mat.singular?
	
		v = Vector[
			r2**2 - r1**2 + a1**2 - a2**2 + b1**2 - b2**2,
			r3**2 - r2**2 + a2**2 - a3**2 + b2**2 - b3**2
			]
	
		x, y =  *(mat.inv * v)
		d = r1**2 - (x-a1)**2 - (y-b1)**2
		next if d < 0
		z = sqrt(d)
	
		if anchors.all?{|a, b, r| (x-a)**2 + (y-b)**2 + z**2 <= r**2 + EPS}
			max = z if z > max
		end
	end
	p max
end