#ifndef _WIN32
#include<iostream>
#endif

#include <complex>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <iomanip>
using namespace std;


#define FOR(i,bg,ed) for(int i = (bg);<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back

#define IL inline
namespace geo{
	typedef double D;
	typedef bool B;
	typedef complex<D> P;
#define X real()
#define Y imag()
	B comp(const P& l, const P& r)
	{
		return (l.X == r.X) ? l.Y < r.Y : l.X < r.X;
	}
	typedef pair<P, P> L;
	typedef pair<P, P> LS;
	typedef pair<P, D> C;
	typedef vector<P> Poly;
	const D EPS = 1e-8;

	//Decomposition Macro
#define DCI(a,b,l) P(a),(b);tie(a,b)=l;
#define DCc(a,b,c) P(a);D(b);tie(a,b)=c;

	//A dot B
	IL D dot(P a, P b)
	{
		return a.X*b.X + a.Y*b.Y;
	}
	IL D cross(P a, P b)
	{
		return a.X*b.Y - a.Y*b.X;
	}
	IL D ccw(P a, P b, P c)
	{
		return cross(b - a, c - a);
	}

	IL int sgn(P a, P b, P c){
		if (cross(b - a, c - a) > EPS)return 1;
		if (cross(b - a, c - a) < -EPS)return -1;
		if (dot(b - a, c - a) < -EPS)return 2;
		if (dot(a - b, c - b) < -EPS)return -2;
		return 0;
	}
	IL D signed_distance_P_L(P p, L l){
		DCI(a, b, l);
		return cross(b - a, p - a) / abs(b - a);
	}
	IL D dinstance_P_L(P p, L l){
		return abs(signed_distance_P_L(p, l));
	}
	IL D distance_P_LS(P p, LS ls){
		DCI(a, b, ls);
		if (dot(b - a, p - a) < EPS)return abs(p - a);
		if (dot(a - b, p - b) < EPS)return abs(p - b);
		return abs(cross(b - a, p - a)) / abs(b - a);
	}

	IL B is_L_L(L p, L q){
		DCI(a, b, p);
		DCI(c, d, q);
		return abs(cross(a - b, c - d))>EPS ||
			abs(cross(a - b, d - b)) < EPS; 
	}
	IL B is_LS_LS(LS p, LS q){
		DCI(a, b, p);
		DCI(c, d, q);
		return sgn(a, b, c) * sgn(a, b, d) <= 0 &&
			sgn(c, d, a) * sgn(c, d, b) <= 0;
	}
	IL D distance_LS_LS(LS p, LS q){
		if (is_LS_LS(p, q))
			return 0;
		return
			min({ distance_P_LS(p.fi, q) ,
			 distance_P_LS(p.se, q) ,
			 distance_P_LS(q.fi, p) ,
			 distance_P_LS(q.se, p) });
	}
	IL P cross_point_L_L(L p, L q){
		DCI(a, b, p);
		D d1 = signed_distance_P_L(a, q);
		D d2 = signed_distance_P_L(b, q);
		return (a*d2 - b*d1) / (d2 - d1);
	}
}

using namespace geo;


int main()
{
	int n;

	cin >> n;
	while (n--){
		D x1, x2, x3, y1, y2, y3, x4, y4;

		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

		P p(x1,y1),q(x2,y2),r(x3,y3),s(x4,y4);

		LS pq(p, q), rs(r, s);
		cout<<fixed;
		cout << setprecision(11);

		auto ans = distance_LS_LS(pq, rs);
		cout << ans  << endl;
	}
	return 0;
}