#include<bits/stdc++.h>
using namespace std;

using ld=long double;
using P=complex<ld>;

const int PREC=100;
const ld EPS=1e-8;

using VP = vector<P>;
struct C { P p; ld r; };
const ld eps = 1e-9, pi = acos(-1.0);
VP is_cc(C c1, C c2){
  VP res;
  ld d = abs(c1.p - c2.p);
  ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
  ld dfr = c1.r * c1.r - rc * rc;
  if (abs(dfr) < eps) dfr = 0.0;
  else if (dfr < 0.0) return res; // no intersection
  ld rs = sqrt(dfr);
  P diff = (c2.p-c1.p)/d;
  res.push_back(c1.p + diff * P(rc, rs));
  if (dfr != 0.0) res.push_back(c1.p + diff * P(rc, -rs));
  return res;
}
vector<P> ccp(P x0,ld r0,P x1,ld r1){
    VP res=is_cc(C{x0,r0},C{x1,r1});
    res.push_back(x0);
    res.push_back(x1);
    return res;
}

bool check(ld h,vector<P>& p,vector<ld> &l){
    int n=p.size();
    vector<ld> tr(n);
    for(int i=0;i<n;i++){
        if(l[i]<h) return false;
        tr[i]=sqrt(l[i]*l[i]-h*h);
    }
    bool res=false;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            vector<P> testP=ccp(p[i],tr[i],p[j],tr[j]);
            for(int k=0;k<testP.size();k++){
                bool isok=true;
                for(int l=0;l<n;l++){
                    isok&=(abs(testP[k]-p[l])<tr[l]+EPS);
                }
                res|=isok;
            }
        }
    }
    return res;
}
ld solve(vector<P> &p,vector<ld> &l){
    if(p.size()==1) return l[0];
    ld lb=0;
    ld ub=1e18;
    for(int i=0;i<PREC;i++){
        ld mid=(lb+ub)/2;
        if(check(mid,p,l)){
            lb=mid;
        }
        else{
            ub=mid;
        }
    }
    return lb;
}
int main(){
    int n;
    cout<<setprecision(10)<<fixed;
    while(cin>>n,n){
        vector<P> p(n);
        vector<ld> l(n);
        for(int i=0;i<n;i++){
            ld x,y;
            cin>>x>>y>>l[i];
            p[i]=P(x,y);
        }
        cout<<solve(p,l)<<endl;
    }
    return 0;
}
