require 'matrix'
include Math

EPS = 0.000001

def dist(x1, y1, z1, x2, y2, z2)
	sqrt((x1-x2)**2 + (y1-y2)**2 + (z1-z2)**2)
end

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

	anchors = (1..n).map{gets.split.map &:to_f}
	max_h = -Float::INFINITY

	update_max_h = -> x, y, z do
		max_h = z if z > max_h && anchors.all?{|a, b, r| dist(x, y, z, a, b, 0) <= r + EPS}
	end
	
	anchors.each {|x, y, z| update_max_h[x, y, z]}
	
	anchors.combination(2) do |u, v|
		u, v = v, u if u[-1] < v[-1]
		(a1, b1, r1), (a2, b2, r2) = u, v
		d = 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)
		update_max_h[x, y, z]
	end
	
	anchors.combination(3) do |(a1, b1, r1), (a2, b2, r2), (a3, b3, r3)|
		begin	
			x, y = *Matrix[
				[a1-a2, b1-b2],
				[a2-a3, b2-b3]
			].inv * Vector[
				(r2**2 - r1**2 + a1**2 - a2**2 + b1**2 - b2**2) / 2,
				(r3**2 - r2**2 + a2**2 - a3**2 + b2**2 - b3**2) / 2,
			]
		
			z = sqrt(r1**2 - (x-a1)**2 - (y-b1)**2)
		
			update_max_h[x, y, z]
		rescue
		end
	end

	p max_h
end