#include<stdio.h>
#include<math.h>
double max,x[20],y[20],l[20];
int n;
double g(double a,double b){
  int i;
  double d,h=1e9;
  for(i=0;i<n;i++){
    d=l[i]*l[i]-((x[i]-a)*(x[i]-a)+(y[i]-b)*(y[i]-b));
    if(h>d)h=d;
  }
  //if(h<0)return 0;
  return h;
}  
int f(double a,double b){
  double h=g(a,b);//printf("h=%f\n",h);
  if(max<h){
    max=h;
    return 1;
  }
  return 0;
}
int main(){
  int i;
  double a,b,c,d,na,nb,nc,nd,e=1e-12;
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%lf %lf %lf",&x[i],&y[i],&l[i]);
    a=b=-100;
    c=d=100;
    while(hypot(d-b,c-a)>e){
      max=-1*1e9;
      if(f((a+a+c)/3.0,(b+b+d)/3.0)){
	na=a;
	nb=b;
	nc=(a+c+c)/3.0;
	nd=(b+d+d)/3.0;
      }
      if(f((a+c+c)/3.0,(b+b+d)/3.0)){
	na=(a+a+c)/3.0;
	nb=b;
	nc=c;
	nd=(b+d+d)/3.0;
      }
      if(f((a+a+c)/3.0,(b+d+d)/3.0)){
	na=a;
	nb=(b+b+d)/3.0;
	nc=(a+c+c)/3.0;
	nd=d;
      }
      if(f((a+c+c)/3.0,(b+d+d)/3.0)){
	na=(a+a+c)/3.0;
	nb=(b+b+d)/3.0;
	nc=c;
	nd=d;
      }
      // printf("%f\n",max);
      a=na;
      b=nb;
      c=nc;
      d=nd;
      //printf("%f %f %f %f\n",a,b,c,d);
    }
    printf("%f\n",sqrt(g(a,b)));
  }
  return 0;
}