#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

const double PI=acos(-1);

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
};
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
Point operator+(Point a,Point b){
	return Point(a.x+b.x,a.y+b.y);
}
Point operator-(Point a,Point b){
	return Point(a.x-b.x,a.y-b.y);
}
Point operator*(double c,Point p){
	return Point(c*p.x,c*p.y);
}
Point operator/(Point p,double c){
	return Point(p.x/c,p.y/c);
}
double Abs(Point p){
	return sqrt(p.x*p.x+p.y*p.y);
}
Point Rot(Point p,double t){
	return Point(cos(t)*p.x-sin(t)*p.y,sin(t)*p.x+cos(t)*p.y);
}

struct Circle{
	Point center;
	double radius;
	Circle(){}
	Circle(Point c,double r):center(c),radius(r){}
	Circle(double x,double y,double r):center(x,y),radius(r){}
};
bool operator==(Circle a,Circle b){
	return a.center==b.center && abs(a.radius-b.radius)<EPS;
}

int IntersectCC(Circle c1,Circle c2){
	if(c1==c2)
		return INFTY;
	double r1=c1.radius,r2=c2.radius,d=Abs(c1.center-c2.center);
	if(d>r1+r2+EPS || d<abs(r1-r2)-EPS)
		return 0;
	if(abs(d-(r1+r2))<EPS || abs(d-abs(r1-r2))<EPS)
		return 1;
	return 2;
}

pair<Point,Point> InterPointCC(Circle c1,Circle c2){
	Point p1=c1.center,p2=c2.center;
	double r1=c1.radius,r2=c2.radius;
	double d=Abs(p1-p2);
	double a=(d*d+r1*r1-r2*r2)/(2*d);
	double s=sqrt(r1*r1-a*a);
	return mp(p1+a/d*(p2-p1)+s*Rot((p2-p1)/d,PI/2),
			  p1+a/d*(p2-p1)-s*Rot((p2-p1)/d,PI/2));
}

bool ok(const vi& xs,const vi& ys,const vi& ls,double z)
{
	int n=xs.size();
	vd rs(n);
	rep(i,n) rs[i]=sqrt(ls[i]*ls[i]-z*z);
	
	vector<Point> ps;
	rep(i,n) ps.push_back(Point(xs[i],ys[i]));
	
	rep(i,n) repi(j,i+1,n){
		Circle c1(xs[i],ys[i],rs[i]),c2(xs[j],ys[j],rs[j]);
		int inter=IntersectCC(c1,c2);
		assert(inter!=INFTY);
		if(inter>=1){
			double r1=c1.radius,r2=c2.radius;
			double d=Abs(c2.center-c1.center);
			double cos_t=(r2*r2-r1*r1-d*d)/(2*r1*d);
			ps.push_back(c1.center+r1*cos_t/d*(c2.center-c1.center));
		}
		if(inter==2){
			auto temp=InterPointCC(c1,c2);
			ps.push_back(temp.first);
			ps.push_back(temp.second);
		}
	}
	
	for(Point p:ps){
		bool ok=true;
		rep(i,n)
			ok&=Abs(p-Point(xs[i],ys[i]))<rs[i]+EPS;
		if(ok) return true;
	}
	
	return false;
}

int main()
{
	for(int n;cin>>n,n;){
		vi xs(n),ys(n),ls(n);
		rep(i,n) cin>>xs[i]>>ys[i]>>ls[i];
		
		double lo=0,hi=*min_element(all(ls));
		rep(_,52){
			double z=(lo+hi)/2;
			if(ok(xs,ys,ls,z))
				lo=z;
			else
				hi=z;
		}
		double res=(lo+hi)/2;
		printf("%.10f\n",res);
	}
}

Measured memory_bytes: 1232