#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define EPS 1e-10

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0) return 0;
		double x[10], y[10], l[10];
		for(int i=0; i<n; i++){
			int x1, y1, l1;
			scanf("%d %d %d", &x1, &y1, &l1);
			x[i]=(double)x1, y[i]=(double)y1, l[i]=(double)l1;
		}
		if(n==1){
			printf("%.7lf\n", l[0]);
			continue;
		}
		double h1=1.0, h2=300.0;
		for(int t=0; t<100; t++){
			double h=(h1+h2)/2.0;
			bool e=0;
			double r[10];
			for(int i=0; i<n; i++){
				if(l[i]<h+EPS){
					e=1;
					break;
				}
				r[i]=sqrt(l[i]*l[i]-h*h);
			}
			if(e==1){
				h2=h;
				continue;
			}
			bool nn[10]={};
			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
					double d=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
					if(abs(r[i]-r[j])>=d-EPS){
						if(r[i]>r[j]){
							nn[i]=1;
						}else{
							nn[j]=1;
						}
					}
					if(r[i]+r[j]<d+EPS){
						e=1;
					}
				}
			}
			if(e==1){
				h2=h;
				continue;
			}
          int count=0;
          for(int i=0; i<n; i++){
            if(nn[i]==0) count++;
          }
          if(count<=2){
            h1=h;
            continue;
          }
			for(int i=0; i<n; i++){
				for(int j=i+1; j<n; j++){
                  if(i==j) continue;
					if(nn[i]==1 || nn[j]==1) continue;
					double s=x[i]*x[i]-x[j]*x[j]+y[i]*y[i]-y[j]*y[j]-l[i]*l[i]+l[j]*l[j];
					double x1, y1, x2, y2;
					if(abs(y[i]-y[j])<EPS){
						x1=s/(2.0*(x[i]-x[j]));
						x2=x1;
						if(l[i]*l[i]-h*h<(x1-x[i])*(x1-x[i])+EPS){
							y1=y[i], y2=y[i];
						}else{
							y1=sqrt(l[i]*l[i]-h*h-(x1-x[i])*(x1-x[i]))+y[i];
							y2=-sqrt(l[i]*l[i]-h*h-(x1-x[i])*(x1-x[i]))+y[i];
						}
					}else{
						double t1=(x[i]-x[j])/(y[i]-y[j]);
						s/=(y[i]-y[j]);
                      	s/=2.0;
						double a=1.0+t1*t1;
						double b=x[i]+t1*(s-y[i]);
						double c=x[i]*x[i]+(s-y[i])*(s-y[i])-l[i]*l[i]+h*h;
						if(b*b<a*c+EPS){
							x1=b, x2=b;
						}else{
							x1=(b+sqrt(b*b-a*c))/a;
							x2=(b-sqrt(b*b-a*c))/a;
						}
						y1=-t1*x1+s;
						y2=-t1*x2+s;
					}
					bool e1=0;
					for(int k=0; k<n; k++){
                      if(k==i || k==j || nn[k]==1) continue;
						if((x1-x[k])*(x1-x[k])+(y1-y[k])*(y1-y[k])>l[k]*l[k]-h*h-EPS){
							e1=1;
							break;
						}
					}
					if(e1==0){
						e=1;
						break;
					}
					e1=0;
					for(int k=0; k<n; k++){
                      if(k==i || k==j || nn[k]==1) continue;
						if((x2-x[k])*(x2-x[k])+(y2-y[k])*(y2-y[k])>l[k]*l[k]-h*h-EPS){
							e1=1;
							break;
						}
					}
					if(e1==0){
						e=1;
						break;
					}
				}
				if(e==1) break;
            }
			if(e==1){
				h1=h;
			}else{
				h2=h;
			}
		}
		printf("%.7lf\n", h1);
	}
	return 0;
}
