#include <cstdio>
#include <complex>
#include <iostream>
#include <utility>
#include <vector>
#define EPS (1e-10)
#define X real()
#define Y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P, double> Rope;

double cross(P a, P b){
  return a.X*b.Y - a.Y*b.X;
}

Rope integrate2(Rope x, Rope y){
  P s = x.first, t = y.first;
  double a = x.second, b = y.second, c_square = norm(s-t);
  if(c_square < EPS) return Rope(s,min(a,b));
  double k = (a*a - b*b + c_square)/c_square/2.0;
  P p = (1-k)*s + k*t;
  double h_square = a*a - norm(p-s);
  return Rope(p, sqrt(max(h_square,0.0)));
}

Rope integrate3(Rope x, Rope y, Rope z){
  //??????????????¬????????¨??????
  P s = x.first, t = y.first, u = z.first;
  double a = x.second, b = y.second, c = z.second;
  if(norm(s-t) < EPS) return integrate2(z, Rope(s,min(a,b)));
  if(norm(t-u) < EPS) return integrate2(x, Rope(t,min(b,c)));
  if(norm(u-s) < EPS) return integrate2(y, Rope(u,min(c,a)));
  double px = ((norm(t) - norm(s) + a*a - b*b)*(u.Y-s.Y) - (norm(u) - norm(s) + a*a - c*c)*(t.Y-s.Y)) / 2.0 / cross(t-s,u-s);
  double py = ((norm(t) - norm(s) + a*a - b*b)*(u.X-s.X) - (norm(u) - norm(s) + a*a - c*c)*(t.X-s.X)) / 2.0 / cross(u-s,t-s);
  P p = P(px, py);
  double h_square = a*a - norm(p-s);
  return Rope(p, sqrt(max(h_square, 0.0)));
}

double solve(vector<Rope> r){
  int n = r.size();
  double ret = -1;
  for(int i = 0; i < n; ++i){
    for(int j = i; j < n; ++j){
      for(int k = j; k < n; ++k){
	Rope x = integrate3(r[i], r[j], r[k]);//?????¬????????????????????¨??????
	double h = x.second;
	if(h < ret) continue;
	P p = x.first;
	bool f = true;
	for(int l = 0; l < n; ++l){
	  if(h*h + norm(p-r[l].first) > r[l].second*r[l].second + EPS){
	    f = false;
	    break;
	  }
	}
	if(f) ret = max(ret, h);
      }
    }
  }
  return ret;
}


int main(){
  int n;
  while(cin >> n, n){
    vector<Rope> R(n);
    double x, y, l;
    for(int i = 0; i < n; ++i){
      cin >> x >> y >> l;
      R[i] = Rope(P(x,y),l);
    }
    printf("%.10lf\n", solve(R));
  }
  return 0;
}