#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define repl(i,a,b) for(i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)

#define EPS 1e-9

#define bool int
#define false 0
#define true 1

#define max(x,y) x>y?x:y
#define maxch(x,y) x=max(x,y)

//typedef vector<double> vec;
//typedef vector<vec> mat;

void swap(double* a,double* b){
	double tmp=*a;*a=*b;*b=tmp;
}

double X[2];

void gauss_jordan(const double A[2][2],const double b[]){
	int n=2;
	double B[n][n+1];
	int i,j,k;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			B[i][j]=A[i][j];
		}
		B[i][n]=b[i];
	}
	X[0]=X[1]=-114514;
	for(i=0;i<n;i++){
		int piv=0;
		for(j=i;j<n;j++){
			if(fabs(B[j][i])>fabs(B[piv][i]))piv=j;
		}
		rep(j,n+1)swap(&B[i][j],&B[piv][j]);
		if(fabs(B[i][i])<EPS)return;
		for(j=i+1;j<=n;j++)B[i][j]/=B[i][i];
		for(j=0;j<n;j++){
			if(i!=j){
				for(k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
			}
		}
	}
	for(i=0;i<n;i++)X[i]=B[i][n];
	return;
}

int n;
double x[11],y[11],l[11];

bool judge(double xx,double yy,double zz){
	bool ok=true;
	int i;
	rep(i,n){
		if(pow(xx-x[i],2)+pow(yy-y[i],2)+pow(zz,2)-pow(l[i],2)>EPS)ok=false;
	}
	return ok;
}

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		int i,j,k;
		rep(i,n)scanf("%lf%lf%lf",x+i,y+i,l+i);
		double res=0;
		{ /// 1
			rep(i,n){
				if(judge(x[i],y[i],l[i])){
					maxch(res,l[i]);
				}
			}
		}
		{ /// 2
			rep(i,n)rep(j,i){
				if(pow(x[i]-x[j],2)+pow(y[i]-y[j],2)-pow(l[i]+l[j],2)>EPS)continue;
				double d=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
				double xx=(l[i]*l[i]-l[j]*l[j]+d*d)/(2*d);
				double vx=(xx/d)*x[j]+((d-xx)/d)*x[i];
				double vy=(xx/d)*y[j]+((d-xx)/d)*y[i];
				if(l[i]*l[i]-xx*xx<EPS)continue;
				double vz=sqrt(l[i]*l[i]-xx*xx);
				if(judge(vx,vy,vz)){
					maxch(res,vz);
				}
			}
		}
		{ /// 3
			rep(i,n)rep(j,i)rep(k,j){
				double A[2][2];
				double b[2];
				A[0][0]=2*(x[j]-x[i]); A[0][1]=2*(y[j]-y[i]);
				A[1][0]=2*(x[k]-x[i]); A[1][1]=2*(y[k]-y[i]);
				b[0]=l[i]*l[i]-l[j]*l[j]-(x[i]+x[j])*(x[i]-x[j])-(y[i]+y[j])*(y[i]-y[j]);
				b[1]=l[i]*l[i]-l[k]*l[k]-(x[i]+x[k])*(x[i]-x[k])-(y[i]+y[k])*(y[i]-y[k]);
				gauss_jordan(A,b);
				if(X[0]==-114514)continue;
				else{
					double vx=X[0], vy=X[1];
					if(l[i]*l[i]-pow(vx-x[i],2)-pow(vy-y[i],2)<EPS)continue;
					double vz=sqrt(l[i]*l[i]-pow(vx-x[i],2)-pow(vy-y[i],2));
					if(judge(vx,vy,vz)){
						maxch(res,vz);
					}
				}
			}
		}
		printf("%.10f\n",res);
	}
	return 0;
}