#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef struct dataSet{
    int x;
    int y;
    int l;
} Data;

typedef struct pointSet{
    double x;
    double y;
    double z;
} Point;

Data data[15];
int n;

double solve();
double one();
double two();
Point twoPoint(int i, int j);
double three();
Point threePoint(int i, int j, int k);
double distance(Point p1, Point p2);
int isOneAble(Point p, int avoid);
int isTwoAble(Point p, int avoid1, int avoid2);
int isThreeAble(Point p, int avoid1, int avoid2, int avoid3);

double solve(){
    double oneh, twoh, threeh;
    oneh = one();
    if(oneh!=0) return oneh;
    else{
        twoh = two();
        threeh = three();
        if(twoh > threeh) return twoh;
        else return threeh;
    }
}

double one(){
    int i=0, avoid;
    Point p;
    double tmph = 1000;
    for(i=0;i<n;++i){
        if(tmph > data[i].l){
            tmph = data[i].l;
            p.x = data[i].x;
            p.y = data[i].y;
            p.z = data[i].l;
            avoid = i;
        }
    }
    if(isOneAble(p, avoid)) return tmph;
    else return 0;
}

double two(){
    int i=0, j=0;
    double maxh = 0;
    Point p;
    for(i=0;i<n;++i){
        for(j=i+1;j<n;++j){
            p = twoPoint(i, j);
            if(p.z==-1) continue;
            if(isTwoAble(p, i, j)) if(maxh < p.z) maxh = p.z;
        }
    }
    return maxh;
}

Point twoPoint(int i, int j){
    Point p, p1, p2;
    double dis, dissub, h2, l1 = data[i].l, l2 = data[j].l, x1 = data[i].x, x2 = data[j].x, y1 = data[i].y, y2 = data[j].y;
    p1.x = data[i].x; p1.y = data[i].y; p1.z = 0;
    p2.x = data[j].x; p2.y = data[j].y; p2.z = 0;
    dis = distance(p1, p2);
    h2 = (4*dis*dis*l2*l2 - dis*dis*dis*dis + 2*dis*dis*l1*l1 - 2*dis*dis*l2*l2 + 2*l1*l1*l2*l2 - l1*l1*l1*l1 - l2*l2*l2*l2)/(4*dis*dis);
    if((l1+l2)<dis) p.z = -1;
    else if(h2<0) p.z = -1;
    else p.z = sqrt(h2);
    dissub = (dis*dis+l1*l1-l2*l2)/(2*dis);
    p.x = x1 + (x2-x1)*dissub/dis;
    p.y = y1 + (y2-y1)*dissub/dis;
    return p;
}

double three(){
    int i=0, j=0, k=0;
    double maxh = 0;
    Point p;
    for(i=0;i<n;++i){
        for(j=i+1;j<n;++j){
            for(k=j+1;k<n;++k){
                p = threePoint(i, j, k);
                if(p.z==-1) continue;
                if(isThreeAble(p, i, j, k)) if(maxh < p.z) maxh = p.z;
            }
        }
    }
    return maxh;
}

Point threePoint(int i, int j, int k){
    Point p, p1, p2, p3;
    double mom, dis, dissub, h2,
    l1 = data[i].l, l2 = data[j].l, l3 = data[k].l,
    x1 = data[i].x, x2 = data[j].x, x3 = data[k].x,
    y1 = data[i].y, y2 = data[j].y, y3 = data[k].y;
    /*p1.x = data[i].x; p1.y = data[i].y; p1.z = 0;
    p2.x = data[j].x; p2.y = data[j].y; p2.z = 0;
    p3.x = data[k].x; p3.y = data[k].y; p3.z = 0;*/
    mom = (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1);
    if(mom==0) p.z = -1;
    else{
        p.x = (((l1*l1-x1*x1-y1*y1-l2*l2+x2*x2+y2*y2)*(y3-y1)-(l1*l1-x1*x1-y1*y1-l3*l3+x3*x3+y3*y3)*(y2-y1))/2)/mom;
        p.y = (((l1*l1-x1*x1-y1*y1-l2*l2+x2*x2+y2*y2)*(x3-x1)-(l1*l1-x1*x1-y1*y1-l3*l3+x3*x3+y3*y3)*(x2-x1))/2)/(-mom);
        h2 = l1*l1 - (x1-p.x)*(x1-p.x) - (y1-p.y)*(y1-p.y);
        if(h2<0) p.z = -1;
        else p.z = sqrt(h2);
    }
    return p;
}

double distance(Point p1, Point p2){
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}

int isOneAble(Point p, int avoid){
    int i=0;
    Point check;
    for(i=0;i<n;++i){
        if(i==avoid) continue;
        check.x = data[i].x;
        check.y = data[i].y;
        check.z = 0;
        double dis = distance(p, check);
        if(dis > data[i].l) return 0;
    }
    return 1;
}

int isTwoAble(Point p, int avoid1, int avoid2){
    int i=0;
    Point check;
    for(i=0;i<n;++i){
        if(i==avoid1 || i==avoid2) continue;
        check.x = data[i].x;
        check.y = data[i].y;
        check.z = 0;
        double dis = distance(p, check);
        if(dis > data[i].l) return 0;
    }
    return 1;
}

int isThreeAble(Point p, int avoid1, int avoid2, int avoid3){
    int i=0;
    Point check;
    for(i=0;i<n;++i){
        if(i==avoid1 || i==avoid2 || i==avoid3) continue;
        check.x = data[i].x;
        check.y = data[i].y;
        check.z = 0;
        double dis = distance(p, check);
        if(dis > data[i].l) return 0;
    }
    return 1;
}

int main(void){
    while(1){
        int i=0;
        scanf("%d", &n);
        if(n==0) break;
        for(i=0;i<n;++i) scanf("%d %d %d", &data[i].x, &data[i].y, &data[i].l);
        double maxh = solve();
        printf("%.6f\n", maxh);
    }
    return 0;
}
