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:
#include <bits/stdc++.h>
using namespace std;

typedef long double Real;
typedef complex<Real> Point;
typedef vector<Point> Polygon;
struct Line {
	Line(){}
	Line(Point p, Point q): p(p), q(q){}
	Point p, q;
};
typedef Line Segment;
struct Circle {
	Circle(){}
	Circle(Point p, Real r): p(p), r(r){}
	Point p;
	Real r;
};

#define X real
#define Y imag

const Real PI = acos(Real(-1));
const Real EPS = 1e-12;

inline int sgn(Real a){
	if (abs(a) < EPS) return 0;
	return a < 0.0 ? -1 : 1;
}

inline bool eq(Real a, Real b){ return sgn(a - b) == 0; }
inline bool neq(Real a, Real b){ return sgn(a - b) != 0; }
inline bool lt(Real a, Real b){ return sgn(a - b) == -1; }
inline bool leq(Real a, Real b){ return sgn(a - b) <= 0; }
inline bool gt(Real a, Real b){ return sgn(a - b) == 1; }
inline bool geq(Real a, Real b){ return sgn(a - b) >= 0; }

Real sq(Real a){ return a * a; }

Real dot(Point a, Point b){ return X(conj(a) * b); }
Real cross(Point a, Point b){ return Y(conj(a) * b); }

bool orthogonal(Line l, Line m){
	return sgn(dot(l.q - l.p, m.q - m.p)) == 0;
}

bool parallel(Line l, Line m){
	return sgn(cross(l.q - l.p, m.q - m.p)) == 0;
}

Point project(Line l, Point p){
	Point t = l.q - l.p;
	Real r = dot(p - l.p, t) / norm(t);
	return l.p + t * r;
}

Point reflect(Line l, Point p){
	return p + (project(l, p) - p) * Real(2.0);
}

int ccw(Point a, Point b, Point c){
	Point u = b - a, v = c - a;
	if (sgn(cross(u, v)) == 1) return 1;		// ccw
	if (sgn(cross(u, v)) == -1) return -1;	// cw
	if (sgn(dot(a, b)) == -1) return 2;			// back
	if (lt(norm(a), norm(b))) return -2;		// front
	return 0;																// on
}

bool intersectLL(Line l, Line m){
	if (!parallel(l, m)) return true;
	return parallel(l, Line(l.p, m.p));
}

bool intersectLS(Line l, Segment s){
	return sgn(cross(l.q - l.p, s.p - l.p)) * sgn(cross(l.q - l.p, s.q - l.p)) <= 0;
}

bool intersectLP(Line l, Point p){
	return parallel(l, Line(l.p, p));
}

bool intersectSS(Segment s, Segment t){
	return ccw(s.p, s.q, t.p) * ccw(s.p, s.q, t.q) <= 0
		&& ccw(t.p, t.q, s.p) * ccw(t.p, t.q, s.q) <= 0;
}

Real distanceLP(Line l, Point p){
	return abs(cross(l.q - l.p, p - l.p) / abs(l.q - l.p));
}

Real distanceLL(Line l, Line m){
	if (intersectLL(l, m)) return 0.0;
	return distanceLP(l, m.p);
}

Real distanceLS(Line l, Segment s){
	if (intersectLS(l, s)) return 0.0;
	return min(distanceLP(l, s.p), distanceLP(l, s.q));
}

Real distanceSP(Segment s, Point p){
	if (sgn(dot(s.q - s.p, p - s.p)) <= 0) return abs(p - s.p);
	if (sgn(dot(s.p - s.q, p - s.q)) <= 0) return abs(p - s.q);
	return distanceLP(s, p);
}

Real distanceSS(Segment s, Segment t){
	if (intersectSS(s, t)) return 0.0;
	return min(
		min(distanceSP(s, t.p), distanceSP(s, t.q)),
		min(distanceSP(t, s.p), distanceSP(t, s.q))
	);
}

bool intersectCL(Circle c, Line l){
	return leq(distanceLP(l, c.p), c.r);
}

bool intersectCS(Circle c, Segment s){
	return leq(distanceSP(s, c.p), c.r);
}

bool intersectCP(Circle c, Point p){
	return leq(norm(c.p - p), sq(c.r));
}

bool intersectCC(Circle c, Circle d){
	return leq(norm(c.p - d.p), sq(c.r + d.r));
}

pair<Point, Point> crossPointsCL(Circle c, Line l){
	Point pr = project(l, c.p);
	Point e = (l.q - l.p) / abs(l.q - l.p);
	Real t = sqrt(sq(c.r) - norm(pr - c.r));
	return make_pair(pr + e * t, pr - e * t);
}

pair<Point, Point> crossPointsCC(Circle c, Circle d){
	Real ds = abs(d.p - c.p);
	Real a = acos((sq(c.r) + sq(ds) - sq(d.r)) / (2 * c.r * ds));
	Real t = arg(d.p - c.p);
	return make_pair(c.p + polar(c.r, t + a), c.p + polar(c.r, t - a));
}

bool contains(Circle c, Circle d){ // d in c
	return leq(c.r + abs(c.p - d.p), d.r);
}

int n;
Real x[10], y[10], l[10];

bool ok(Real h)
{
	Circle c[10];
	for (int i = 0; i < n; i++){
		Real r = sqrt(sq(l[i]) - sq(h));
		c[i] = Circle(Point(x[i], y[i]), r);
	}

	for (int i = 0; i < n; i++){
		bool f = true;
		for (int j = 0; j < n; j++){
			if (!intersectCP(c[j], c[i].p)) f = false;
		}
		if (f) return true;
	}

	vector<Point> cps;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (!intersectCC(c[i], c[j])) return false;
			if (contains(c[i], c[j])) continue;
			if (contains(c[j], c[i])) continue;
			auto cp = crossPointsCC(c[i], c[j]);
			cps.push_back(cp.first);
			cps.push_back(cp.second);
		}
	}
	
	for (auto cp : cps){
		bool f = true;
		for (int i = 0; i < n; i++){
			if (!intersectCP(c[i], cp)) f = false;
		}
		if (f) return true;
	}

	return false;
}

int main()
{
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			cin >> x[i] >> y[i] >> l[i];
		}
		Real lb = 0.0, ub = *min_element(l, l + n);
		for (int j = 0; j < 100; j++){
			Real md = (lb + ub) / 2;
			(ok(md) ? lb : ub) = md;
		}
		cout << fixed << setprecision(20) << lb << endl;
	}
}