#include <stdio.h>
#include <math.h>
double answer();
double searchY(double X);
double search(double X, double Y);

int n;
double x[10]; double y[10]; double l[10];

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

double answer()
{
    int j;
    double l = -100.0, r = 100.0;
    double a, b;
    for(j = 50; j >= 0; j--)
    {
        a = (2*l + r) / 3;
        b = (l + 2*r) / 3;
        if(searchY(a) > searchY(b)) r = b; else l = a;
    }
    return sqrt(searchY(l));
}

double searchY(double X)
{
    int j;
    double l = -100.0, r = 100.0, a, b;
    for(j = 50; j >= 0; j--)
    {
        a = (2*l + r) / 3;
        b = (l + 2*r) / 3;
        if(search(X, a) > search(X, b)) r = b; else l = a;
    }
    return search(X, l);
}

double search(double X, double Y)
{
    int j;
    double t, s = 100000000;
    for(j = 0; j < n; j++)
    {
        t = l[j]*l[j] - (X-x[j])*(X-x[j]) - (Y-y[j])*(Y-y[j]);
        if(t < s) s = t;
    }
    return s;
}
