#include <cmath>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
struct vec{
    double x,y;
    vec(){x=y=0.0;};
    vec(double x, double y): x(x), y(y){};
    inline double add(double a, double b){
        return abs(a+b)<(1e-10)*(abs(a)+abs(b))?0.0:a+b;
    }
    vec operator-(vec b){
        return vec(add(x,-b.x),add(y,-b.y));
    }
    vec operator+(vec b){
        return vec(add(x,b.x),add(y,b.y));
    }
    vec operator*(double d){
        return vec(x*d,y*d);
    }
    bool operator==(vec b){
        return x==b.x&&y==b.y;
    }
    bool operator!=(vec b){
        return x!=b.x||y!=b.y;
    }
    double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    double norm(){
        return hypot(x,y);
    }
};

pair<vec,vec> cross_point(vec&C1, vec&C2, double r1, double r2){
    vec e1,e2,P1,P2;
    double d=(C2-C1).norm();
    e1=(C2-C1)*(1/d);
    double theta = acos((r1*r1+(C2-C1).dot(C2-C1)-r2*r2)/(2*r1*d));
    e2.x=cos(theta)*e1.x-sin(theta)*e1.y, e2.y=sin(theta)*e1.x+cos(theta)*e1.y;
    P1=C1+e2*r1;
    e2.x=cos(theta)*e1.x+sin(theta)*e1.y, e2.y=-sin(theta)*e1.x+cos(theta)*e1.y;
    P2=C1+e2*r1;
    if(P1.x==P2.x){
        if(P1.y<P2.y) return make_pair(P1,P2);
        else return make_pair(P2,P1);
    }else{
        if(P1.x<P2.x)return make_pair(P1,P2);
        else return make_pair(P2,P1);
    }
}

double radius(double h, double l){
    return sqrt(l*l-h*h);
}
int n;
vector<vec> V;
vector<double> L;

bool iswrap(vec point, vector<double> &LL){
    for(int i=0;i<n;i++){
        double d = (V[i]-point).norm();
        if(LL[i]+1e-9<d) return false;
    }
    return true;
}

bool test(double h){
    vector<double> LL(n);
    for(int i=0;i<n;i++) LL[i]=radius(h,L[i]);
    for(int i=0;i<n;i++){
        if(iswrap(V[i],LL)) return true;
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            //テゥツ崢「テ」ツつ古」ツ?ヲテ」ツつ?
            double d = (V[i]-V[j]).norm();
            if(d>LL[i]+LL[j]){
                return false;
            }
            //テ・ツ??・ツ個?
            if(d+min(LL[i],LL[j])<max(LL[i],LL[j])){
                continue;
            }
            //テ、ツコツ、テ・ツキツョ
            auto PP = cross_point(V[i],V[j],LL[i],LL[j]);
            if(iswrap(PP.first,LL)||iswrap(PP.second,LL)) return true;
        }
    }
    return false;
}

int main(){
    cout<<fixed;
    cout.precision(7);
    while(cin>>n,n){
        V.clear();
        L.clear();
        for(int i=0;i<n;i++){
            int x,y,l;
            cin>>x>>y>>l;
            V.emplace_back(x,y);
            L.push_back(l);
        }
        double lb=1,ub=1000;
        for(auto l:L) ub=min(ub,l);
        int cnt=50;
        while(cnt--){
            double mid=(ub+lb)/2;
            if(test(mid)){
                lb=mid;
            }else{
                ub=mid;
            }
        }
        cout<<ub<<endl;
    }

    return 0;
}