#include <cmath>
#include <cstdio>
#include <complex>
#include <algorithm>
using namespace std;
// ------ Defines ------ //
#define Point complex<long double>
#define px real()
#define py imag()
// ------ Classes ------ //
class Segment {
public:
	Point p1, p2;
	Segment(Point p1_, Point p2_) : p1(p1_), p2(p2_) {};
	Segment(long double p1x, long double p1y, long double p2x, long double p2y) : p1(Point(p1x, p1y)), p2(Point(p2x, p2y)) {};
	friend bool operator==(const Segment& s1, const Segment& s2) { return (s1.p1 == s2.p1 && s1.p2 == s2.p2) || (s1.p1 == s2.p2 && s1.p2 == s2.p1); }
	friend bool operator!=(const Segment& s1, const Segment& s2) { return !(s1 == s2); }
};
class Line {
public:
	Point p1, p2;
	Line(Point p1_, Point p2_) : p1(p1_), p2(p2_) {};
	Line(long double p1x, long double p1y, long double p2x, long double p2y) : p1(Point(p1x, p1y)), p2(Point(p2x, p2y)) {};
	friend bool operator==(const Line& s1, const Line& s2) { return (s1.p1 == s2.p1 && s1.p2 == s2.p2) || (s1.p1 == s2.p2 && s1.p2 == s2.p1); }
	friend bool operator!=(const Line& s1, const Line& s2) { return !(s1 == s2); }
};
// ------ Functions ------ //
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 = p1 - p0, b = 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 Line& a, const Point& b) {
	return abs(crs(a.p2 - a.p1, b - a.p1) / abs(a.p2 - a.p1));
}
long double dst(const Segment& a, const Point& b) {
	if (dot(a.p2 - a.p1, b - a.p1) < 0.0) return abs(b - a.p1);
	if (dot(a.p1 - a.p2, b - a.p2) < 0.0) return abs(b - a.p2);
	return abs(crs(a.p2 - a.p1, b - a.p1) / abs(a.p2 - a.p1));
}
long double dst(const Segment& a, const Segment& b) {
	if (its(a, b)) return 0;
	return min({ dst(a, b.p1), dst(a, b.p2), dst(b, a.p1), dst(b, a.p2) });
}
int q, px1, py1, px2, py2, qx1, qy1, qx2, qy2;
int main() {
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d%d%d%d%d%d%d%d", &px1, &py1, &px2, &py2, &qx1, &qy1, &qx2, &qy2);
		printf("%.9Lf\n", dst(Segment(px1, py1, px2, py2), Segment(qx1, qy1, qx2, qy2)));
	}
	return 0;
}