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 <iostream>
#include <cmath>
#include <vector>
using namespace std;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define pb push_back

typedef long double ld;
const ld PI = 3.141592653589793238462643383279;

struct po{
	ld x;
	ld y;
	po(ld a){ x = a; y = 0; }
	po(ld a,ld b){ x = a; y = b; }
	po(){}
	inline ld operator()(const po& rhs) const {
		return x*rhs.x+y*rhs.y;
	}
	inline ld norm() {
		return sqrt((*this)(*this));
	}
	inline po& operator+=(const po& rhs){
		x += rhs.x;
		y += rhs.y;
		return *this;
	}
	inline po& operator-=(const po& rhs){
		x -= rhs.x;
		y -= rhs.y;
		return *this;
	}
	inline po& operator*=(const po& rhs){
		ld x_ = x*rhs.x-y*rhs.y;
		y = x*rhs.y+y*rhs.x;
		x = x_;
		return *this;
	}
	inline po& operator/=(const po& rhs){
		ld x_ = x*rhs.x+y*rhs.y;
		y = -x*rhs.y+y*rhs.x;
		x = x_;
		ld nor = rhs(rhs);
		x /= nor;
		y /= nor;
		return *this;
	}
	inline void in(){
		scanf("%Lf%Lf",&x,&y);
	}
};
inline po operator+(const po& a, const po& b){ return po(a) += b; }
inline po operator-(const po& a, const po& b){ return po(a) -= b; }
inline po operator*(const po& a, const po& b){ return po(a) *= b; }
inline po operator/(const po& a, const po& b){ return po(a) /= b; }

inline po similar(const po& a,const po& b,const po& c,const po& p,const po& q){
	return p+(q-p)*(c-a)/(b-a);
}

typedef pair<po,po> se;
#define fr first
#define sc second

struct li{
	ld a;
	ld b;
	ld c;
	li(po p,po q){
		a = q.y-p.y;
		b = p.x-q.x;
		c = p.y*q.x-p.x*q.y;
	}
	/*explicit li(se s){
		a = s.sc.y-s.fr.y;
		b = s.fr.x-s.sc.x;
		c = s.fr.y*s.sc.x-s.fr.x*s.sc.y;
		li(s.fr,s.sc);
	}*/
	li(){}
	inline ld operator()(const po& p) const {
		return a*p.x+b*p.y+c;
	}
};

void intersect(const li &l,const li &m,po* &ret){
	if(abs(l.a*m.b-m.a*l.b) <= 1e-18){
		ret = nullptr;
		return;
	}
	ret = new po;
	ret->x = -(l.c*m.b-m.c*l.b)/(l.a*m.b-m.a*l.b);
	ret->y = -(l.a*m.c-m.a*l.c)/(l.a*m.b-m.a*l.b);
}
inline bool on(const po &p,const se &s){
	return (s.fr-p)(s.sc-p) <= 1e-9;
}
void intersect(const se &s,const se &t,po* &ret){
	li l = li(s.fr,s.sc);
	li m = li(t.fr,t.sc);
	po *p;
	intersect(l,m,p);
	if(p == nullptr || (on(*p,s)&&on(*p,t)))ret = p;
	else{
		delete p;
		ret = nullptr;
	}
}
inline ld dist(const po &p,const po &q){
	return sqrt((p-q)(p-q));
}
inline li perpen(const po &p,const li &l){
	li ret;
	ret.a = l.b;
	ret.b = -l.a;
	ret.c = l.a*p.y-l.b*p.x;
	return ret;
}
inline po perpen_leg(const po &p,const li &l){
	po ret;
	li m = perpen(p,l);
	ret.x = -(l.c*m.b-m.c*l.b)/(l.a*m.b-m.a*l.b);
	ret.y = -(l.a*m.c-m.a*l.c)/(l.a*m.b-m.a*l.b);
	return ret;
}
inline ld dist(const po &p,const se &s){
	po h = perpen_leg(p,li(s.fr,s.sc));
	if(on(h,s))return dist(p,h);
	else return min( dist(p,s.fr) , dist(p,s.sc) );
}
inline ld dist(const se &s,const se &t){
	po *p;
	intersect(s,t,p);
	if(p != nullptr){
		delete p;
		return 0.0;
	}
	ld ret = min( dist(s.fr,t) , dist(s.sc,t) );
	ret = min( ret , min( dist(t.fr,s) , dist(t.sc,s) ) );
	return ret;
}
inline ld dist(const po &p, const li &l){
	return abs(l(p))/sqrt(l.a*l.a+l.b*l.b);
}

struct ci{
	po c;
	ld r;
	inline bool internal(const po &p){
		return dist(p,c) <= r+1e-9;
	}
};

ci circum(const po &p,const po &q,const po &r){
	ci ret;
	li l = perpen((p+q)/2.0,li(p,q));
	li m = perpen((q+r)/2.0,li(q,r));
	po* _c;
	intersect(l,m,_c);
	if(_c == nullptr){
		ret.c = po(0.0,0.0);
		ret.r = -1.0;
		return ret;
	}
	else {
		ret.c = *_c;
		ret.r = dist(ret.c,p);
		delete _c;
		return ret;
	}
}


void intersect(const li &l, const ci &c, po* &ret1, po* &ret2){
	ld d = dist(c.c,l);
	if(d > c.r+1e-9){
		ret1 = nullptr;
		ret2 = nullptr;
		return;
	}
	po h = perpen_leg(c.c,l);
	if(abs(d-c.r) <= 1e-9){
		ret1 = new po;
		*ret1 = h;
		ret2 = nullptr;
		return;
	}
	ret1 = new po;
	*ret1 = h+(c.c-h)*po(0.0,sqrt((c.r*c.r-d*d)/((c.c-h)(c.c-h))));
	ret2 = new po;
	*ret2 = 2*h-*ret1;
	return;
}
void intersect(const ci &c, const ci &d, po* &ret1, po* &ret2){
	li l;
	l.a = 2*(c.c.x-d.c.x);
	l.b = 2*(c.c.y-d.c.y);
	l.c = d.c(d.c)-d.r*d.r-(c.c(c.c)-c.r*c.r);
	intersect(l,c,ret1,ret2);
}
void tangent(const po &p, const ci &c,li* &ret1,li* &ret2){
	ci d;
	d.c = (p+c.c)/2.0;
	d.r = dist(p,c.c)/2.0;
	po *q,*r;
	intersect(c,d,q,r);
	ret1 = ret2 = nullptr;
	if(q == nullptr)return;
	ret1 = new li;
	*ret1 = li(p,*q);
	delete q;
	if(r == nullptr)return;
	ret2 = new li;
	*ret2 = li(p,*r);
	delete r;
}
void cotan_in(const ci &c, const ci &d, li* &ret1, li* &ret2){
	po p = similar(-c.r,d.r,0.0,c.c,d.c);
	tangent(p,c,ret1,ret2);
}
void cotan_out(const ci &c, const ci &d, li* &ret1, li* &ret2){
	if(abs(c.r-d.r) < 1e-9){
		ret1 = new li;
		ret2 = new li;
		*ret1 = *ret2 = li(c.c,d.c);
		ret1->c += c.r*sqrt(ret1->a*ret1->a+ret1->b*ret1->b);
		ret2->c -= c.r*sqrt(ret1->a*ret1->a+ret1->b*ret1->b);
		return;
	}
	po p = similar(c.r,d.r,0.0,c.c,d.c);
	tangent(p,c,ret1,ret2);
}

int main(){
	int n;
	while(1){
		scanf("%d",&n);
		if(n == 0)break;
		ci p[12];
		rep1(i,n){
			p[i].c.in();
			scanf("%Lf",&p[i].r);
		}
		ld l = 0.0, r = 300.0;
		rep1(i,n){
			ld _l = p[i].r;
			rep1(j,n){
				ld d2 = p[j].r*p[j].r-(p[i].c-p[j].c)(p[i].c-p[j].c);
				if(d2 <= 1e-9)_l = 0.0;
				else _l = min( _l , sqrt(d2) );
			}
			l = max( l , _l );
		}
		while(r-l>0.0000001){
			ld m = (l+r)/2.0;
			bool ret = true;
			ci _p[12];
			rep1(i,n){
				_p[i] = p[i];
				if(_p[i].r <= m+1e-9)ret = false;
				else _p[i].r = sqrt(_p[i].r*_p[i].r-m*m);
			}
			if(!ret){
				r = m;
				continue;
			}
			ret = false;
			vector<po*> vec;
			po *q[2];
			rep1(i,n)for(int j = i+1 ; j <= n ; j ++){
				intersect(_p[i],_p[j],q[0],q[1]);
				rep(k,2)if(q[k] != nullptr)vec.pb(q[k]);
			}
			for(po* _q: vec){
				bool _ret = true;
				rep1(i,n)_ret &= dist(*_q,_p[i].c) <= _p[i].r+1e-9;
				delete _q;
				if(_ret)ret = true;
			}
			if(ret)l = m;
			else r = m;
		}
		printf("%.12f\n",(double)l);
	}
}