Problem: Anchored Balloon

A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation.

<image>
Figure E-1: A balloon and ropes on the ground

Now the balloon takes off, and your task is to find how high the balloon can go up with keeping the rope connections. The positions of the anchors are fixed. The lengths of the ropes and the positions of the anchors are given. You may assume that these ropes have no weight and thus can be straightened up when pulled to whichever directions. Figure E-2 shows the highest position of the balloon for the situation shown in Figure E-1.

<image>
Figure E-2: The highest position of the balloon

Input

The input consists of multiple datasets, each in the following format.

> n
>  x1 y1 l1
>  ...
>  xn yn ln
>

The first line of a dataset contains an integer n (1 ≤ n ≤ 10) representing the number of the ropes. Each of the following n lines contains three integers, xi, yi, and li, separated by a single space. Pi = (xi, yi) represents the position of the anchor connecting the i-th rope, and li represents the length of the rope. You can assume that −100 ≤ xi ≤ 100, −100 ≤ yi ≤ 100, and 1 ≤ li ≤ 300. The balloon is initially placed at (0, 0) on the ground. You can ignore the size of the balloon and the anchors.

You can assume that Pi and Pj represent different positions if i ≠ j. You can also assume that the distance between Pi and (0, 0) is less than or equal to li−1. This means that the balloon can go up at least 1 unit high.

Figures E-1 and E-2 correspond to the first dataset of Sample Input below.

The end of the input is indicated by a line containing a zero.

Output

For each dataset, output a single line containing the maximum height that the balloon can go up. The error of the value should be no greater than 0.00001. No extra characters should appear in the output.

Sample Input


3
10 10 20
10 -10 20
-10 10 120
1
10 10 16
2
10 10 20
10 -10 20
2
100 0 101
-90 0 91
2
0 0 53
30 40 102
3
10 10 20
10 -10 20
-10 -10 20
3
1 5 13
5 -3 13
-3 -3 13
3
98 97 168
-82 -80 193
-99 -96 211
4
90 -100 160
-80 -80 150
90 80 150
80 80 245
4
85 -90 290
-80 -80 220
-85 90 145
85 90 170
5
0 0 4
3 0 5
-3 0 5
0 3 5
0 -3 5
10
95 -93 260
-86 96 211
91 90 177
-81 -80 124
-91 91 144
97 94 165
-90 -86 194
89 85 167
-93 -80 222
92 -84 218
0


Output for the Sample Input


17.3205081
16.0000000
17.3205081
13.8011200
53.0000000
14.1421356
12.0000000
128.3928757
94.1879092
131.1240816
4.0000000
72.2251798






Example

Input

3
10 10 20
10 -10 20
-10 10 120
1
10 10 16
2
10 10 20
10 -10 20
2
100 0 101
-90 0 91
2
0 0 53
30 40 102
3
10 10 20
10 -10 20
-10 -10 20
3
1 5 13
5 -3 13
-3 -3 13
3
98 97 168
-82 -80 193
-99 -96 211
4
90 -100 160
-80 -80 150
90 80 150
80 80 245
4
85 -90 290
-80 -80 220
-85 90 145
85 90 170
5
0 0 4
3 0 5
-3 0 5
0 3 5
0 -3 5
10
95 -93 260
-86 96 211
91 90 177
-81 -80 124
-91 91 144
97 94 165
-90 -86 194
89 85 167
-93 -80 222
92 -84 218
0


Output

17.3205081
16.0000000
17.3205081
13.8011200
53.0000000
14.1421356
12.0000000
128.3928757
94.1879092
131.1240816
4.0000000
72.2251798

Solution (in CPP):

Solution:
#ifndef _WIN32
#include<iostream>
#endif 
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<tuple>
#include<complex>
#include<queue>
#include<functional>
using namespace std;
typedef long long LL;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
template<typename T> bool chmin(T &l, T r) {
	bool res = l > r;
	if (res) {
		l = r;
	}
	return res;
}
#define IL inline
#define X real()
#define Y imag()
typedef double D;

typedef complex<double> P;
typedef pair<P, P> LS;
typedef pair<P, D> C;
const D EPS = 1e-8;
IL D dot(P a, P b) {
	return a.X*b.X + a.Y*b.Y;
}
IL D cross(P a, P b) {
	return a.X*b.Y - a.Y*b.X;
}



struct cww {
	cww() {
		cout << fixed;
		cout << setprecision(10);
	}
}star;
IL D signed_distance_P_L(P p, LS l) {
	P a, b, c = p;
	tie(a, b) = l;
	return cross(b - a, c - a) / abs(b - a);
}
IL D distance_P_LS(P p, LS ls) {
	P a, b, c = p;
	tie(a, b) = ls;
	if (dot(b - a, c - a) < EPS)return abs(c - a);
	if (dot(a - b, c - b) < EPS)return abs(c - b);
	return abs(cross(b - a, c - a)) / abs(b - a);
}

IL bool isintersected_LS_LS(LS p, LS q) {
	P a, b, c, d;
	tie(a, b) = p;
	tie(c, d) = q;
	if (abs(cross(b - a, d - c))<EPS) {
		if (abs(abs(b - c) + abs(a - c) - abs(a - b)) < EPS)return true;
		if (abs(abs(b - d) + abs(a - d) - abs(a - b)) < EPS)return true;
		if (abs(abs(a - c) + abs(a - d) - abs(c - d)) < EPS)return true;
		if (abs(abs(b - c) + abs(b - d) - abs(c - d)) < EPS)return true;

		return false;
	}
	return cross(b - a, c - a)*cross(b - a, d - a) < EPS && cross(d - c, a - c)*cross(d - c, b - c) < EPS;
}
IL D distance_LS_LS(LS p, LS q) {
	if (isintersected_LS_LS(p, q))return 0;
	P a, b, c, d;
	tie(a, b) = p;
	tie(c, d) = q;
	double e, f, g, h;
	e = distance_P_LS(a, q);
	f = distance_P_LS(b, q);
	g = distance_P_LS(c, p);
	h = distance_P_LS(d, p);
	return min({ e,f,g,h });
}
P rot(P p, double r) {
	return P(p.X*cos(r) - p.Y*sin(r), p.X*sin(r) + p.Y*cos(r));
}
IL bool isintersected_C_C(C p, C q) {
	P cp, cq;
	D rp, rq;
	tie(cp, rp) = p;
	tie(cq, rq) = q;
	D d = abs(cp - cq);
	return abs(rp - rq) < d + EPS&&d < rp + rq + EPS;
}
IL LS cross_C_C(C p, C q) {
	P cp, cq;
	D rp, rq;
	tie(cp, rp) = p;
	tie(cq, rq) = q;
	D d = abs(cp - cq);
	D rc = (d*d +rp*rp - rq*rq)/(2*d);
	D rs = sqrt(rp*rp - rc*rc);
	P diff = (cq - cp) / d;
	return LS(cp + P(rc, rs)*diff, cp + P(rc, -rs)*diff);
}

const D PI = acos(-1);
typedef pair<double, int> pp;
typedef priority_queue<pp, vector<pp>, greater<pp>> QUE;
int main() {
	int N;
	while (cin >> N, N) {
		vector<P> xy(N);
		vector<D> len(N);
		REP(i, N) {
			double x, y;
			cin >> x >> y>>len[i];
			xy[i] = P(x, y);
		}
		double lb = 0;
		double ub = 400;
		REP(loop, 100) {
			const D mid = (lb + ub) / 2;
			vector<C> cir(N);
			bool flag = true;
			REP(i, N) {
				double l = len[i] * len[i] - mid*mid;
				if (l < 0) { flag = false; break; }
				cir[i] = C(xy[i], sqrt(l));
			}
			if (flag == false) {
				ub = mid; continue;
			}
			vector<P> nobu;
			REP(i, N)nobu.push_back(xy[i]);
			REP(i, N) {
				REP(j, N) {
					if (i != j) {
						if (!isintersected_C_C(cir[i], cir[j]))continue;
						auto hiro = cross_C_C(cir[i], cir[j]);
						nobu.push_back(hiro.first);
						nobu.push_back(hiro.second);
					}
				}
			}
			flag = false;
			for (auto &p : nobu) {
				bool btk=true;
				REP(i, N) {
					auto d = abs(p - xy[i]);
					if (d*d + mid*mid >EPS+ len[i] * len[i])
						btk = false;
				}
				if (btk)flag = true;
			}


			if (flag)lb = mid;
			else ub = mid;
		}
		cout << lb << endl;
	}
	return 0;
}