#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};
VP crosspointCC(C a, C b){
    VP ps;
    if(a.r < b.r) swap(a,b);
    P ab = b.p-a.p;
    double dist = abs(ab);
    if(EQ(dist, a.r+b.r) || EQ(dist, a.r-b.r)){
        ps.push_back( a.p +ab*(a.r/dist) );
        return ps;
    }
    if(dist > a.r +b.r || dist < abs(a.r-b.r)){
        return ps;
    }
    double l = ((a.r*a.r -b.r*b.r)/dist +dist) /2;
    double n = sqrt(a.r*a.r -l*l);
    P mid = a.p + ab*l/dist;
    P ort = ab *(n/dist) *P(0,1);
    ps.push_back(mid+ort);
    ps.push_back(mid-ort);
    return ps;
}

const int nrep = 50;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<double> x(n), y(n), l(n);
		double lmin=INF;
		for(int i=0; i<n; i++){
			cin >> x[i] >> y[i] >> l[i];
			lmin = min(lmin, l[i]);
		}
		
		double lb=0, ub=lmin;
		for(int i=0; i<nrep; i++){
			double mid = (lb+ub)/2;
			vector<C> c(n);
			for(int j=0; j<n; j++){
				c[j] = C(P(x[j],y[j]), sqrt(l[j]*l[j] -mid*mid));
			}
			bool success = false;
			for(int s=0; s<n && !success; s++){
				for(int t=s+1; t<n && !success; t++){
					VP cp = crosspointCC(c[s], c[t]);
					for(int j=0; j<(int)cp.size(); j++){
						bool flag = true;
						for(int k=0; k<n; k++){
							if(abs(cp[j]-c[k].p) > c[k].r +EPS){
								flag = false;
								break;
							}
						}
						if(flag){
							success = true;
							break;
						}
					}
				}
			}
			for(int j=0; j<n; j++){
				bool flag = true;
				for(int k=0; k<n; k++){
					if(abs(c[j].p-c[k].p) > c[k].r +EPS){
						flag = false;
						break;
					}
				}
				if(flag){
					success = true;
					break;
				}
			}
			if(success){
				lb = mid;
			}else{
				ub = mid;
			}
		}
		
		cout << fixed;
		cout << setprecision(10);
		cout << (lb+ub)/2 << endl;
	}
	return 0;
}