#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

typedef complex<ld> Point;
ld dot(Point a, Point b) { return real(conj(a)*b); }
ld cross(Point a, Point b) { return imag(conj(a)*b); }
namespace std {
	bool operator<(const Point &lhs, const Point &rhs) {
		return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
	}
}
struct Line {
	Point a, b;
};
struct Circle {
	Point p; ld r;
};
namespace std {
	bool operator<(const Circle &lhs, const Circle &rhs) {
		if (lhs.r != rhs.r)return lhs.r < rhs.r;
		return lhs.p < rhs.p;
	}
}

vector<Point> is_cc(Circle c1, Circle c2) {
	vector<Point> res;
	ld d = abs(c1.p - c2.p);
	ld rc = (d*d + c1.r*c1.r - c2.r*c2.r) / (2 * d);
	ld dfr = c1.r*c1.r - rc * rc;
	if (abs(dfr) < eps)dfr = 0.0;
	if (dfr < 0.0)return res;
	ld rs = sqrt(dfr);
	Point diff = (c2.p - c1.p) / d;
	res.push_back(c1.p + diff * Point(rc, rs));
	if (dfr != 0.0)res.push_back(c1.p + diff * Point(rc, -rs));
	return res;
}

// most in_circle point
int calc(vector<Circle> c) {
	if (c.size() <= 1)return c.size();
	int res = 0;
	rep(i, c.size()) {
		int num = 1;
		vector<pair<ld, int>> u;
		int cur = 0;
		rep(j, c.size()) {
			if (i == j)continue;
			ld dist = abs(c[j].p - c[i].p);
			if (dist + c[i].r <= c[j].r) {
				num++;
			}
			else if (dist > c[i].r + c[j].r)continue;
			else {
				vector<Point> v = is_cc(c[i], c[j]);
				if (v.size() <= 1)continue;
				ld t1 = atan2(imag(v[0]) - imag(c[i].p), real(v[0]) - real(c[i].p));
				ld t2 = atan2(imag(v[1]) - imag(c[i].p), real(v[1]) - real(c[i].p));
				u.push_back({ t1,0 });
				u.push_back({ t2,1 });
				if (t2 > t1) {
					cur++;
				}
			}
		}
		sort(u.begin(), u.end());
		int len = u.size();
		rep(i, len)u.push_back({ u[i].first + 2 * pi,u[i].second });
		len = u.size();
		int ma = 0;
		rep(i, len) {
			if (u[i].second)cur++;
			else cur--;
			ma = max(ma, cur);
		}
		res = max(res, ma + num);
	}
	return res;
}
int n;
void solve() {
	vector<Point> p(n);
	vector<ld> l(n);
	ld ri = mod;
	rep(i, n) {
		ld x, y; cin >> x >> y;
		p[i] = { x,y }; cin >> l[i];
		ri = min(ri, l[i]);
	}
	ld le = 1;
	rep(aa, 100) {
		ld mid = (le + ri) / 2.0;
		vector<Circle> c;
		rep(i, n) {
			ld r = sqrt(l[i] * l[i] - mid * mid);
			c.push_back({ p[i],r });
		}
		int num = calc(c);
		//cout << mid << " !! " << num << endl;
		if (num == n) {
			le = mid;
		}
		else {
			ri = mid;
		}
	}
	cout << le << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(7);
	//init();
	while (cin >> n, n) {
		solve();
	}
	//stop
	return 0;
}




Measured memory_bytes: 3372