#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
struct Point { long double px, py; };
struct Segment { Point p1, p2; };
Point Minus(Point a, Point b) { Point G; G.px = a.px - b.px; G.py = a.py - b.py; return G; }
long double Abs(Point a) { return sqrt(a.px*a.px + a.py*a.py); }
long double norm(Point a) { return a.px*a.px + a.py*a.py; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int ccw(Point p0, Point p1, Point p2) {
	Point a = Minus(p1, p0), b = Minus(p2, p0);
	if (crs(a, b) > 1e-10) return 1;
	if (crs(a, b) < -1e-10) return -1;
	if (dot(a, b) < -1e-10) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool its(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool its(Segment s1, Segment s2) {
	return its(s1.p1, s1.p2, s2.p1, s2.p2);
}
long double dst(const Segment& a, const Point& b) {
	if (dot(Minus(a.p2, a.p1), Minus(b, a.p1)) < 0.0) return Abs(Minus(b, a.p1));
	if (dot(Minus(a.p1, a.p2), Minus(b, a.p2)) < 0.0) return Abs(Minus(b, a.p2));
	return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1)));
}
int main() {
	Point P1, P2, P3, P4; Segment M1, M2;
	int T; cin >> T;
	for (int i = 0; i < T; i++) {
		cin >> P1.px >> P1.py >> P2.px >> P2.py;
		cin >> P3.px >> P3.py >> P4.px >> P4.py;
		M1.p1 = P1; M1.p2 = P2; M2.p1 = P3; M2.p2 = P4;
		long double res = min(dst(M1, P3), dst(M1, P4));
		res = min(res, min(dst(M2, P1), dst(M2, P2)));
		if (its(M1, M2) == true) { res = 0.0; }
		cout << fixed << setprecision(1919) << res << endl;
	}
	return 0;
}