#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> P;

struct Circle{
  double r;
  P c;
  Circle(double r=0.0, P c = P(0,0)):r(r),c(c){}
  bool operator < (const Circle &c) const {
    return r < c.r;
  }
};

const double EPS = 1e-8;

int n;
double hi;
Circle v[11];

bool equal(double a, double b){ return fabs(a-b) < EPS;}

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

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

bool isIntersectCP(P p, Circle c){
  return abs(c.c-p) < c.r || equal(abs(c.c-p),c.r);
}

vector<P> intersectCC(Circle C1, Circle C2){
  vector<P> res;
  double r1 = C1.r, r2 = C2.r, d;
  P p1 = C1.c, p2 = C2.c;
  d = abs(p1-p2);
  if(d < EPS && abs(r1-r2) < EPS) return res;
  if(r1 + r2 < d - EPS || d + EPS < abs(r1-r2)) return res;

  double a = (r1*r1 - r2*r2 + d*d) / (2*d);
  double h = sqrt(max(r1*r1 - a*a, 0.0));
  P tmp1 = p1 + a / d * (p2-p1);
  P tmp2 = h / d * (p2-p1);

  if(abs(tmp2) < EPS) res.push_back(tmp1);
  else{
    res.push_back(P(real(tmp1) - imag(tmp2), imag(tmp1) + real(tmp2)));
    res.push_back(P(real(tmp1) + imag(tmp2), imag(tmp1) - real(tmp2)));
  }
  return res;
}

bool func(vector<Circle> w){
  bool f = false;
  int ws = w.size();
  if(ws == 1) return true;

  //内側に円があれば、交わっていなくてもtrue
  f = false;
  for(int i=1;i<ws;i++) {
    if(abs(w[i].c-w[0].c) > w[i].r-w[0].r && !equal(abs(w[i].c-w[0].c),w[i].r-w[0].r)){
      f = true;
      break;
    }
  }
  if(!f)  return true;


  //円の交点を求め、１つでも全ての円の内側・境界に存在するならtrue
  vector<P> p;
  for(int i=0;i<ws;i++){
    for(int j=i+1;j<ws;j++){
      vector<P> aa = intersectCC(w[i],w[j]);
      for(int k=0;k<aa.size();k++) p.push_back(aa[k]);
    }
  }
  for(int i=0;i<p.size();i++){
    int j;
    for(j=0;j<ws;j++){
      if(!isIntersectCP(p[i],w[j])) break;
    }
    if(j == ws) return true;
  }
  return false;
}

bool check(double h){
  if(n == 1) return h < v[0].r;
  vector<Circle> w;

  for(int i=0;i<n;i++) w.push_back(Circle(sqrt(v[i].r*v[i].r - h*h), v[i].c));
  sort(w.begin(),w.end());
  return func(w);
}

void solve(){
  double c,lo=0.0;
  for(int i=0;i<100;i++){
    c = (lo + hi) / 2.0;
    if(check(c)) lo = c;
    else hi = c;
  }
  printf("%.7f\n",hi);
}

int main(){
  while(cin >> n && n){
    hi = 400.0;
    for(int i=0;i<n;i++){
      double x,y;
      cin >> x >> y >> v[i].r;
      v[i].c = P(x,y);
      hi = min(hi, v[i].r);
    }
    solve();
  }

}