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 <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

using T = long double;
const T INF = 1e10;
const T EPS = 1e-10;
const T PI = acos(-1.0);
T torad(int deg) {return (T)(deg) * PI / 180;}
T todeg(T ang) {return ang * 180 / PI;}
template <typename T> inline bool eq(T p, T q) { return abs(p - q) < EPS; }
inline int sgn(T x) { return (T(0) < x) - (x < T(0)); }

/* Point */
using P = complex<T>;
#define x real()
#define y imag()
inline T dot(P v, P w) { return (conj(v) * w).x; }
inline T cross(P v, P w) { return (conj(v) * w).y; }
inline T orient(P a, P b, P c) { return cross(b - a, c - a); }
inline bool isOrth(P v, P w) { return dot(v, w) == 0; }
inline bool isPara(P v, P w) { return cross(v, w) == 0; }
inline P unit(P v) { return v / abs(v); }
inline P translate(P p, P v) { return p + v; }
inline P scale(P p, P c, T k) { return c + (p - c) * k; }
inline P rot(P p, T a) { return p * polar(T(1), a); }
inline P rot90(P p) { return {-p.y, p.x}; }
inline P linearTransform(P p, P q, P fp, P fq, P r) { return fp + (r - p) * (fq - fp) / (q - p); }
bool cmpX(const P& a, const P& b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
bool cmpY(const P& a, const P& b) { return a.y != b.y ? a.y < b.y : a.x < b.x; }
namespace std {
    istream& operator>>(istream& is, P& p) { T xx, yy; is >> xx >> yy; p = P(xx, yy); return is; }
    bool operator < (const P& a, const P& b) { return cmpX(a, b); }
}

/* Line */
struct L : array<P, 2> {
    P v; T c;
    L() = default;
    explicit L(P a, P b) : array<P, 2>({a, b}), v(b - a), c(cross(v, a)) {}
    T side(P p) { return cross(v, p) - c; }
    P proj(P p) { return p - rot90(v) * side(p) / norm(v); }
    P refl(P p) { return p - rot90(v) * T(2) * side(p) / norm(v); }
    bool onLine(P p) { return abs(side(p)) < EPS; }
    bool onSegment(P p) { return onLine(p) && dot(this->operator[](0) - p, this->operator[](1) - p) <= EPS; }
    friend istream& operator>>(istream& is, L& l) { P p, q; is >> p >> q; l = L(p, q); return is; }
    friend ostream& operator<<(ostream& os, const L& l) { return os << '{' << l[0] << ", " << l[1] << '}'; }
};

/* Circle */
struct C : P {
    T r;
    C() = default;
    C(P p, T r) : P(p), r(r) {}
    friend istream& operator>>(istream& is, C& c) { P p; T r; is >> p >> r; c = C(p, r); return is; }
    friend ostream& operator<<(ostream& os, const C& c) { return os << '(' << c.x << ", " << c.y << ", " << c.r << ')'; }
};

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > EPS) return 1;         // counter clockwise
    if (cross(b, c) < -EPS) return -1;       // clockwise
    if (dot(b, c) < -EPS) return 2;          // c--a--b on line
    if (norm(b) < norm(c) - EPS) return -2;  // a--b--c on line or a==b
    return 0;                                // a--c--b on line or a==c or b==c
}

// intersect
bool isInterPL(P p, L l) { return (ccw(l[0], l[1], p) != 1); }
bool isInterPS(P p, L s) { return (ccw(s[0], s[1], p) == 0); }
bool isInterLL(L l, L m) { return (!isPara(l.v, m.v)); }
bool isInterLS(L l, L s) {
    if (eq(s[0], s[1])) return isInterPL(s[0], l);
    return (ccw(l[0], l[1], s[0]) * ccw(l[0], l[1], s[1]) <= 0);
}
bool isInterSS(L s, L t) {
    if (eq(s[0], s[1])) return isInterPL(s[0], t);
    if (eq(t[0], t[1])) return isInterPL(t[0], s);
    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);
}
int isInterCC(C a, C b) {
    T d = abs(b - a);
    if (a == b && a.r == b.r) return 0;         // ∞ cp (A = B)
    if (a.r + d - b.r < -EPS) return +1;        // 0 cp (A in B)
    if (b.r + d - a.r < -EPS) return -1;        // 0 cp (B in A)
    if (abs(a.r + d - b.r) < EPS) return +2;    // 1 cp (A in B)
    if (abs(b.r + d - a.r) < EPS) return -2;    // 1 cp (B in A)
    if (abs(a.r + b.r - d) < EPS) return 3;     // 1 cp (outside)
    if (a.r + b.r - d < -EPS) return 4;         // 0 cp (outside)
    return 5;                                   // 2 cp
}

// distance
T distancePL(P p, L l) { return (abs(p - l.proj(p))); }
T distancePS(P p, L s) {
    P h = s.proj(p);
    if (isInterPS(h, s)) return abs(p - h);
    return min(abs(p - s[0]), abs(p - s[1]));
}
T distanceLL(L l, L m) {
    if (isInterLL(l, m)) return 0.0;
    return distancePL(m[0], l);
}
T distanceLS(L l, L s) {
    if (isInterLS(l, s)) return 0;
    return min(distancePL(s[0], l), distancePL(s[1], l));
}
T distanceSS(L s, L t) {
    if (isInterSS(s, t)) return 0;
    return min({distancePS(s[0], t), distancePS(s[1], t), distancePS(t[0], s), distancePS(t[1], s)});
}

// crosspoint
vector<P> crosspointLL(L l, L m) {
    if (!isInterLL(l, m)) return vector<P>();
    vector<P> res;
    T d = cross(m[1] - m[0], l[1] - l[0]);
    res.push_back(l[0] + (l[1] - l[0]) * cross(m[1] - m[0], m[1] - l[0]) / d);
    return res;
}
vector<P> crosspointLS(L l, L s) {
    if (!isInterLS(l, s)) return vector<P>();
    vector<P> res;
    T d = cross(s[1] - s[0], l[1] - l[0]);
    res.push_back(l[0] + (l[1] - l[0]) * cross(s[1] - s[0], s[1] - l[0]) / d);
    return res;
}
vector<P> crosspointLC(L l, C c, bool dupl = false) {
    if (abs(c - l.proj(c)) > c.r) return vector<P>();
    vector<P> res;
    T d = distancePL(c, l), h2 = c.r * c.r - d * d;
    assert(h2 >= -EPS);
    P p = l.proj(c), h = l.v * sqrt(h2) / abs(l.v);
    res.push_back(p - h);
    if (dupl || abs(h) > EPS) res.push_back(p + h);
    return res;
}
vector<P> crosspointSS(L s, L t) {
    if (!isInterSS(s, t)) return vector<P>();
    vector<P> res;
    T d = cross(t[1] - t[0], s[1] - s[0]);
    if (d) {
        res.push_back(s[0] + (s[1] - s[0]) * cross(t[1] - t[0], t[1] - s[0]) / d);
    } else {
        if (ccw(s[0], s[1], t[0]) == 0) res.push_back(t[0]);
        if (ccw(s[0], s[1], t[1]) == 0) res.push_back(t[1]);
        if (ccw(t[0], t[1], s[0]) == 0) res.push_back(s[0]);
        if (ccw(t[0], t[1], s[1]) == 0) res.push_back(s[1]);
    }
    return res;
}
vector<P> crosspointSC(L s, C c, bool dupl = false) {
    if (abs(c - s.proj(c)) > c.r) return vector<P>();
    vector<P> res;
    T d = distancePL(c, s), h2 = c.r * c.r - d * d;
    assert(h2 >= -EPS);
    P p = s.proj(c), h = s.v * sqrt(h2) / abs(s.v);
    if (isInterPS(p - h, s)) res.push_back(p - h);
    if (dupl || (abs(h) > EPS && isInterPS(p + h, s))) res.push_back(p + h);
    return res;
}
vector<P> crosspointCC(C c1, C c2, bool dupl = false) {
    P d = c2 - c1; T d2 = norm(d);
    if (d2 == 0) { assert(c1.r != c2.r); return vector<P>(); }
    vector<P> res;
    T pd = (d2 + c1.r * c1.r - c2.r * c2.r) / 2;
    T h2 = c1.r * c1.r - pd * pd / d2;
    if (h2 >= 0) {
        P p = c1 + d * pd / d2, h = rot90(d) * sqrt(h2 / d2);
        res.push_back(p - h);
        if (dupl || abs(h) > EPS) res.push_back(p + h);
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    int n;
    while (cin >> n, n) {
        vector<P> ps(n);
        vector<int> l(n);
        REP (i, n) cin >> ps[i] >> l[i];

        int j = -1;
        REP (i, n) if (j == -1 || l[i] < l[j] - EPS) j = i;

        bool f = true;
        REP (i, n) if (i != j) {
            T r = sqrt(l[i] * l[i] - l[j] * l[j]);
            f &= (abs(ps[i] - ps[j]) <= r + EPS);
        }

        if (f) {
            cout << (T)l[j] << endl;
            continue;
        }

        auto check = [&](T m) -> bool {
            vector<C> cs(n);
            REP (i, n) cs[i] = C(ps[i], sqrt(l[i] * l[i] - m * m));
            vector<P> cps;
            REP (i, n) FOR (j, i + 1, n) {
                for (P& p : crosspointCC(cs[i], cs[j])) {
                    cps.emplace_back(p);
                }
            }
            for (P& p : cps) {
                bool ok = true;
                REP (i, n) {
                    ok &= (abs(cs[i] - p) <= cs[i].r + EPS);
                }
                if (ok) return true;
            }
            return false;
        };

        T ok = 0, ng = l[j];
        REP (i, 100) {
            T m = (ok + ng) / 2;
            if (check(m)) ok = m;
            else ng = m;
        }
        cout << ok << endl;
    }
}