Problem: Anchored Balloon

A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation.

<image>
Figure E-1: A balloon and ropes on the ground

Now the balloon takes off, and your task is to find how high the balloon can go up with keeping the rope connections. The positions of the anchors are fixed. The lengths of the ropes and the positions of the anchors are given. You may assume that these ropes have no weight and thus can be straightened up when pulled to whichever directions. Figure E-2 shows the highest position of the balloon for the situation shown in Figure E-1.

<image>
Figure E-2: The highest position of the balloon

Input

The input consists of multiple datasets, each in the following format.

> n
>  x1 y1 l1
>  ...
>  xn yn ln
>

The first line of a dataset contains an integer n (1 ≤ n ≤ 10) representing the number of the ropes. Each of the following n lines contains three integers, xi, yi, and li, separated by a single space. Pi = (xi, yi) represents the position of the anchor connecting the i-th rope, and li represents the length of the rope. You can assume that −100 ≤ xi ≤ 100, −100 ≤ yi ≤ 100, and 1 ≤ li ≤ 300. The balloon is initially placed at (0, 0) on the ground. You can ignore the size of the balloon and the anchors.

You can assume that Pi and Pj represent different positions if i ≠ j. You can also assume that the distance between Pi and (0, 0) is less than or equal to li−1. This means that the balloon can go up at least 1 unit high.

Figures E-1 and E-2 correspond to the first dataset of Sample Input below.

The end of the input is indicated by a line containing a zero.

Output

For each dataset, output a single line containing the maximum height that the balloon can go up. The error of the value should be no greater than 0.00001. No extra characters should appear in the output.

Sample Input


3
10 10 20
10 -10 20
-10 10 120
1
10 10 16
2
10 10 20
10 -10 20
2
100 0 101
-90 0 91
2
0 0 53
30 40 102
3
10 10 20
10 -10 20
-10 -10 20
3
1 5 13
5 -3 13
-3 -3 13
3
98 97 168
-82 -80 193
-99 -96 211
4
90 -100 160
-80 -80 150
90 80 150
80 80 245
4
85 -90 290
-80 -80 220
-85 90 145
85 90 170
5
0 0 4
3 0 5
-3 0 5
0 3 5
0 -3 5
10
95 -93 260
-86 96 211
91 90 177
-81 -80 124
-91 91 144
97 94 165
-90 -86 194
89 85 167
-93 -80 222
92 -84 218
0


Output for the Sample Input


17.3205081
16.0000000
17.3205081
13.8011200
53.0000000
14.1421356
12.0000000
128.3928757
94.1879092
131.1240816
4.0000000
72.2251798






Example

Input

3
10 10 20
10 -10 20
-10 10 120
1
10 10 16
2
10 10 20
10 -10 20
2
100 0 101
-90 0 91
2
0 0 53
30 40 102
3
10 10 20
10 -10 20
-10 -10 20
3
1 5 13
5 -3 13
-3 -3 13
3
98 97 168
-82 -80 193
-99 -96 211
4
90 -100 160
-80 -80 150
90 80 150
80 80 245
4
85 -90 290
-80 -80 220
-85 90 145
85 90 170
5
0 0 4
3 0 5
-3 0 5
0 3 5
0 -3 5
10
95 -93 260
-86 96 211
91 90 177
-81 -80 124
-91 91 144
97 94 165
-90 -86 194
89 85 167
-93 -80 222
92 -84 218
0


Output

17.3205081
16.0000000
17.3205081
13.8011200
53.0000000
14.1421356
12.0000000
128.3928757
94.1879092
131.1240816
4.0000000
72.2251798

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <complex>
#include <iomanip>
#include <cmath>

using namespace std;

typedef complex<double> P;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const double eps = 1e-8, inf = 1e8;

template<typename T> T sqr(T x){return x*x;}

double cross(const P &a, const P &b){
    return imag(conj(a) * b);
}

double dot(const P &a, const P &b){
    return real(conj(a) * b);
}

int ccw(P a, P b, P c){
    b -= a; c -= a;
    if(cross(b, c) > eps)return 1;
    if(cross(b, c) < -eps)return -1;
    if(dot(b, c) < 0)return 2;
    if(norm(b) < norm(c))return -2;
    return 0;
}

struct L:vector<P>{
    L(const P &a, const P &b){
        push_back(a); push_back(b);
    }
};

bool interSS(const L &s, const L &t){
    return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
           ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}

bool interSP(const L &s, const P &p){
    return abs(s[0]-p) + abs(s[1]-p) - abs(s[1]-s[0]) < eps;
}

P xptSS(const L &s, const L &t){
    double d = cross(s[1] - s[0], t[1] - t[0]);
    if(abs(d) < eps){
        if(interSP(t, s[0]))return s[0];
        if(interSP(t, s[1]))return s[1];
        if(interSP(s, t[0]))return t[0];
        return t[1];
    }
    return t[0] + (t[1] - t[0]) * cross(s[1] - s[0], s[1] - t[0]) * (1. / d);
}

struct C:P{
    double r;
    C(const P &a, double r):P(a), r(r){}
};

int overlap(const C &c1, const C &c2){
    if(sqr(c1.r + c2.r) < norm(c1 - c2))return 0;
    if(abs(c1 - c2) + c1.r < c2.r + eps)return -1;
    if(c2.r < c1.r && abs(c1 - c2) + c2.r < c1.r + eps)return 1;
    if(abs(abs(c1 - c2) - c1.r - c2.r) < eps)return -2;
    return 2;
}

vector<P> xptCC(const C &c1, const C &c2){
    vector<P> res;
    double d = abs(c1 - c2);
    if(d < eps || abs(overlap(c1, c2)) != 2)return res;
    double rc = (sqr(d) + sqr(c1.r) - sqr(c2.r)) / (2. * d);
    double rs = sqrt(sqr(c1.r) - sqr(rc));
    P diff = (c2 - c1) / d;
    res.push_back(c1 + diff * P(rc, rs));
    res.push_back(c1 + diff * P(rc, -rs));
    return res;
}

double solve(vector<C> stake){
    vector<P> fixpt(all(stake));
    vector<L> locus;
    rep(i, (int)stake.size())rep(j, i){
        vector<P> xpt = xptCC(stake[i], stake[j]);
        if(xpt.empty())continue;
        fixpt.push_back((xpt[0] + xpt[1]) / 2.);
        locus.emplace_back(xpt[0], xpt[1]);
    }
    rep(i, (int)locus.size())rep(j, i){
        if(!interSS(locus[i], locus[j]))continue;
        fixpt.push_back(xptSS(locus[i], locus[j]));
    }
    double res = 0.;
    for(auto p: fixpt){
        double h = inf;
        for(auto c: stake)h = min(h, sqr(c.r) - norm(c - p));
        res = max(res, h);
    }
    return res;
}

int main(){
    for(int n; cin >> n, n;){
        vector<C> stake;
        rep(i, n){
            int x, y, l;
            cin >> x >> y >> l;
            stake.emplace_back(P(x, y), l);
        }
        cout << fixed << setprecision(7) << sqrt(solve(stake)) << '\n';
    }
    return 0;
}