#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <set>
constexpr double EPSILON = 1e-9;
struct Coordinate {
	double x, y;
	double distance(const Coordinate that) const;
};
struct Angle {
	double sin, cos;
	Angle operator-() const;
	static Angle from_cos(const double cos);
};
struct Vector {
	double dx, dy;
	Vector rotate(const Angle angle) const;
	double length() const;
};
Vector operator*(const Vector vec, const double scala);
Vector operator*(const double scala, const Vector vec);
Vector operator-(const Coordinate to, const Coordinate from);
Coordinate operator+(const Coordinate coord, const Vector vec);
Coordinate operator+(const Vector vec, const Coordinate coord);
struct Circle {
	Coordinate center;
	double radius;
	bool contains(const Coordinate that) const;
	std::vector<Coordinate> cross_points(const Circle that) const;
};
struct Anchor {
	double x, y, length;
	Circle slice(double height) const;
};
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::vector<Anchor> anchors(n); for (auto& a : anchors) std::cin >> a.x >> a.y >> a.length;
		if (n == 1) {
			std::cout << std::setprecision(15) << std::fixed << anchors.front().length << std::endl;
			continue;
		}
		double min = 0;
		double max = std::min_element(anchors.begin(), anchors.end(), [](const Anchor a, const Anchor b) {return a.length < b.length; })->length;
		std::vector<Circle> circles(n);
		for (auto i = 0; i < 60; ++i) {
			const auto mid = (min + max) / 2;
			std::transform(anchors.begin(), anchors.end(), circles.begin(), [mid](const Anchor a) {return a.slice(mid); });
			bool has_intersection = false;
			for (auto i = 0; i < n && !has_intersection; ++i) {
				for (auto j = 0; j < i && !has_intersection; ++j) {
					for (const auto coordinate : circles[i].cross_points(circles[j])) {
						has_intersection = true;
						for (auto k = 0; k < n; ++k) if (i != k && j != k) {
							if (!circles[k].contains(coordinate)) {
								has_intersection = false;
								break;
							}
						}
						if (has_intersection) break;
					}
				}
				if (has_intersection) continue;
				has_intersection = true;
				for (auto j = 0; j < n && has_intersection; ++j) {
					has_intersection = i == j || circles[j].contains(circles[i].center);
				}
			}
			if (has_intersection) min = mid;
			else max = mid;
		}
		std::cout << std::setprecision(15) << std::fixed << max << std::endl;
	}
}


bool Circle::contains(const Coordinate that) const
{
	return center.distance(that) <= radius + EPSILON;
}

std::vector<Coordinate> Circle::cross_points(const Circle that) const
{
	const auto dist = center.distance(that.center);
	if (dist > radius + that.radius + EPSILON) return std::vector<Coordinate>{};
	const auto cos = (radius * radius + dist * dist - that.radius * that.radius) / (2 * radius * dist);
	const auto angle = Angle::from_cos(cos);
	const auto vec = (that.center - center) * (radius / dist);
	return std::vector<Coordinate>{vec.rotate(angle) + center, vec.rotate(-angle) + center};
}

Vector Vector::rotate(const Angle angle) const
{
	return Vector{ dx * angle.cos - dy * angle.sin, dy * angle.cos + dx * angle.sin };
}

double Vector::length() const
{
	return std::sqrt(dx * dx + dy * dy);
}

Angle Angle::operator-() const
{
	return Angle{ -sin, cos };
}

Angle Angle::from_cos(const double cos)
{
	return Angle{ std::sqrt(1 - cos * cos), cos };
}

Vector operator*(const Vector vec, const double scala)
{
	return Vector{ vec.dx * scala, vec.dy * scala };
}

Vector operator*(const double scala, const Vector vec)
{
	return Vector{ scala * vec.dx, scala * vec.dy };
}

Vector operator-(const Coordinate to, const Coordinate from)
{
	return Vector{ to.x - from.x, to.y - from.y };
}
Coordinate operator+(const Coordinate coord, const Vector vec)
{
	return Coordinate{ coord.x + vec.dx, coord.y + vec.dy };
}

Coordinate operator+(const Vector vec, const Coordinate coord)
{
	return Coordinate{ vec.dx + coord.x, vec.dy + coord.y };
}

double Coordinate::distance(const Coordinate that) const
{
	return (*this - that).length();
}

Circle Anchor::slice(double height) const
{
	const auto radius = std::sqrt(length * length - height * height);
	return Circle{ Coordinate{x, y}, radius };
}




Measured memory_bytes: 3372