#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
using namespace std;
const double EPS = 1e-10;
typedef complex<double> P;

bool zero(double a) { return abs(a) <= EPS; }

int n, x[10], y[10], l[10];
P dir[10];
double r[10];

bool canClear(P p, int i1, int i2) {
  for (int i = 0; i < n; i++) if (i != i1 && i != i2 && EPS + r[i] < abs(p - dir[i])) return false;
  return true;
}

bool check(double h) {
  for (int i = 0; i < n; i++) {
    if (-EPS > ((double)l[i] - h)) return false;
    if (zero((double)l[i] - h)) r[i] = 0.0;
    r[i] = sqrt((double)l[i] * l[i] - h * h);
  }
  for (int i = 0; i < n; i++) if (canClear(dir[i], -1, -1)) return true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      double d = abs(dir[j] - dir[i]);
      if (d - r[i] - r[j] > EPS) return false;
      if (r[i] - r[j] - d > EPS) continue;
      if (r[j] - r[i] - d > EPS) continue;
      double A = atan2((dir[j] - dir[i]).imag(), (dir[j] - dir[i]).real());
      double S = acos((d*d + r[i]*r[i] - r[j]*r[j]) / (2 * d * r[i]));
      if (canClear(dir[i] + polar(r[i], A + S), i, j)) return true;
      if (canClear(dir[i] + polar(r[i], A - S), i, j)) return true;
    }
  }
  return false;
}

double getH() {
  double lb = 1.0, ub = 300.0;
  while (!zero(ub - lb)) {
    double ave = (lb + ub) / 2;
    if (check(ave)) lb = ave;
    else ub = ave;
  }
  return lb;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 0; i < n; i++) scanf("%d%d%d", &x[i], &y[i], &l[i]);
    for (int i = 0; i < n; i++) dir[i] = P(x[i], y[i]);
    if (n == 1) printf("%f\n", (double)l[0]);
    else printf("%f\n", getH());
  }
}

