// Arup Guha
// 3/10/2020
// Solution to 2020 UCF HS Problem: In a Jam

import java.util.*;

public class jam {
	
	public static int n;
	public static circle[] list;
	
    public static void main(String[] args) {
		
        Scanner stdin = new Scanner(System.in);
        int nC = stdin.nextInt();

		// Process each case.
        for (int loop=0; loop<nC; loop++) {
            
			// Read in the circles.
			n = stdin.nextInt();
            list = new circle[n];
            for (int i=0; i<n; i++) {
                int x = stdin.nextInt();
                int y = stdin.nextInt();
                int r = stdin.nextInt();
				list[i] = new circle(x, y, r);
            }

			// Do it!
			System.out.printf("%.3f\n",solve());
        }
    }
	
	public static double solve() {
		
		pt origin = new pt(0, 0);
		
		// Will put possible candidates in this list.
		ArrayList<pt> candidates = new ArrayList<pt>();
		
		// These are the points closest to the origin at the edge of each circle.
		// Here we use the loose test, so we test circles with the origin on its boundary.
		for (int i=0; i<n; i++) 
			if (list[i].containsPtLoose(origin)) 
				candidates.add(list[i].nearestPtOut());
			
		// Go through pairs of circles, adding all intersection points.
		for (int i=0; i<n; i++) {
			for (int j=i+1; j<n; j++) {
				ArrayList<pt> ans = (list[i]).intersect(list[j]);
				for (pt p: ans) candidates.add(p);
			}
		}
		
		// Safe initial distance, will get overwritten.
		double res = 10000;
		
		// Test each candidate - update best if necessary.
		for (pt p: candidates) 
			if (test(p)) res = Math.min(res, p.mag());
		
		return res;
	}
	
	// Returns true iff p isn't contained in any circle.
	public static boolean test(pt p) {
		
		// Check all circles. Here we use the strict test (strictly in the circle).
		for (int i=0; i<n; i++)
			if (list[i].containsPtStrict(p)) 
				return false;
			
		// If we get here, we are good.
		return true;
	}
}

// Basic point class
class pt {
	
	public double x;
	public double y;
	
	public pt(double myx, double myy) {
		x = myx;
		y = myy;
	}
	
	public double mag() {
		return Math.sqrt(x*x + y*y);
	}
	
	public double distToPt(pt p) {
		return Math.sqrt( (x-p.x)*(x-p.x) + (y-p.y)*(y-p.y) );
	}
	
	public pt newPtByFactor(double factor) {
		return new pt(factor*x, factor*y);
	}
}

class circle {
	
	final public static double EPS = 1e-9;
	
	public pt center;
	public double r;
	
	public circle(double myx, double myy, double myr) {
		center = new pt(myx, myy);
		r = myr;
	}
	
	// p is strictly within the circle by a boundary of EPS, at least.
	public boolean containsPtStrict(pt p) {
		return center.distToPt(p) < r-EPS;
	}
	
	// p is within EPS of the circle.
	public boolean containsPtLoose(pt p) {
		return center.distToPt(p) < r+EPS;
	}	
	
	// Pre-req: p is in circle. Returns the closest pt outside of the circle.
	public pt nearestPtOut() {
		
		// Direction vector from circle center to origin.
		pt newv = new pt(-center.x, -center.y);
		
		// Distance to travel from (0, 0) to circle edge.
		double newd = r - center.mag();
		
		// Check for div by 0.
		if (newv.mag() > 0)
			return new pt(newd*newv.x/newv.mag(), newd*newv.y/newv.mag());
		
		// Dummy return.
		return new pt(r, 0);
	}
	
	// Returns the intersection points of this and other.
	public ArrayList<pt> intersect(circle other) {
		
		// Store answer here.
		ArrayList<pt> res = new ArrayList<pt>();
		
		// Distance between centers.
		double dBetween = center.distToPt(other.center);
		
		// Circles don't intersect.
		if (dBetween > r + other.r + 1e-9) return res;
		
		// Other non intersect case.
		if (dBetween < Math.abs(r-other.r) + 1e-9) return res;
		
		// One intersection pt - pt on line seg of centers...
		if (Math.abs(dBetween - r - other.r) < 1e-9) {
			pt vect = new pt(other.center.x-center.x, other.center.y-center.y);
			vect = vect.newPtByFactor(r/(r+other.r));
			res.add(new pt(center.x+vect.x, center.y+vect.y));
			return res;
		}
		
		// Get cosine of angle between vector from this circle to other and the vector to
		// the intersection point.
		double cosA = (r*r + dBetween*dBetween - other.r*other.r)/(2*r*dBetween);
		double angle = Math.acos(cosA);
		
		// Angle of vector from this center to other center.
		double origAngle = Math.atan2(other.center.y-center.y, other.center.x-center.x);
		
		// Add angle.
		double ang1 = origAngle + angle;
		res.add(new pt(center.x+r*Math.cos(ang1), center.y+r*Math.sin(ang1)));
		
		// Subtract angle.
		double ang2 = origAngle - angle;
		res.add(new pt(center.x+r*Math.cos(ang2), center.y + r*Math.sin(ang2)));
		return res;
	}
	
}