#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

#define PI 3.14159265358979323846

#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
#define diff(P, i) (next(P,i) - curr(P,i))
#define EQ(x,y) (fabs((x)-(y))<EPS)
#define GE(x,y) ((x)+EPS>(y))
#define LE(x,y) ((x)<(y)+EPS)
enum { OUT, ON, IN };

typedef complex<double> P;
typedef vector<P> G;

namespace std{
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(){}
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

struct C {
  P p; double r;
  C(){}
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > EPS)   return +1;       // counter clockwise
  if (cross(b, c) < -EPS)   return -1;       // clockwise
  if (dot(b, c) < -EPS)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)+EPS) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
P reflection(const L &l, const P &p) {
  return p + 2.0 * (projection(l, p) - p);
}
double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

vector<P> crosspointLC(const L &l, const C &c){
	vector<P> res;
	P p = projection(l, c.p);
	double d1 = abs(p - c.p);
	if(EQ(d1, c.r)){
		res.pb(p);
		return res;
	}
	if(d1 > c.r){
		return res;
	}
	double d2 = sqrt(c.r*c.r - d1*d1);
	P v = d2/abs(l[1] - l[0]) * (l[1] - l[0]);
	res.pb(p + v);
	res.pb(p - v);
	return res;
}

#define sq(x) ((x)*(x))

vector<P> crosspointCC(const C &c1, const C &c2){
	vector<P> res;
	P v = c2.p - c1.p;
	double d = abs(v);
	if(d < EPS){
		if(EQ(c1.r, c2.r)){ // coincide
			res.pb(c1.p + P(c1.r, 0));
		}
		return res;
	}
	vector<double> thetas;
	if(EQ(d, c1.r + c2.r)){
		thetas.pb(0);
	}else if(EQ(d, c1.r - c2.r)){
		thetas.pb(0);
	}else if(EQ(d, c2.r - c1.r)){
		thetas.pb(PI);
	}else if(d > c1.r + c2.r || d < abs(c1.r - c2.r)){
		return res;
	}else{
		double t = acos((sq(c1.r) + sq(d) - sq(c2.r))
			/ (2.0 * c1.r * d));
		thetas.pb(t);
		thetas.pb(-t);
	}
	rep(i, sz(thetas)){
		res.pb(c1.p + c1.r/d * v
			* P(cos(thetas[i]), sin(thetas[i])));
	}
	return res;
}

int n;
P p[11];
double l[11];

void main2(){
	double lo=0,hi=300;
	rep(ii,100){
		double mi=(lo+hi)/2;
		int ok=1;
		C c[11];
		rep(i,n){
			if(mi>l[i]){
				ok=0;break;
			}
			c[i]=C(p[i],sqrt(l[i]*l[i]-mi*mi));
		}
		if(!ok){
			hi=mi;continue;
		}
		vector<P> v;
		rep(i,n)v.pb(p[i]);
		rep(i,n)rep2(j,i+1,n){
			vector<P> w=crosspointCC(c[i],c[j]);
			rep(k,sz(w))v.pb(w[k]);
		}
		ok=0;
		rep(i,sz(v)){
			int ok2=1;
			rep(j,n)if(abs(v[i]-p[j]) > c[j].r+EPS){
				ok2=0;break;
			}
			if(ok2){
				ok=1;break;
			}
		}
		if(ok)lo=mi;
		else hi=mi;
	}
	cout<<setprecision(16)<<lo<<endl;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n && n){
		rep(i,n){
			double x,y;
			cin>>x>>y;
			p[i]=P(x,y);
			cin>>l[i];
		}
		main2();
	}
}

Measured memory_bytes: 1408