#include <bits/stdc++.h>
using namespace std;

constexpr double EPS = 1e-10;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
typedef pair<Point, double> Circle;
typedef vector<Point> Polygon;
double dot(Vector a, Vector b){
	return real(a) * real(b) + imag(a) * imag(b);
}
double cross(Vector a, Vector b){
	return real(a) * imag(b) - imag(a) * real(b);
}
Point project(Line l, Point p){
	Vector base = l.second - l.first;
	base /= abs(base);
	double r = dot(p - l.first, base);
	return l.first + r * base;
}
Point reflect(Line l, Point p){
	return p + (project(l, p) - p) * 2.0;
}
int ccw(Point p0, Point p1, Point p2){
	Vector v = p1 - p0, w = p2 - p0;
	if(cross(v, w) > EPS) return 1; // COUNTER_CLOCKWISE
	if(cross(v, w) < -EPS) return -1; // CLOCKWISE
	if(dot(v, w) < -EPS) return 2; // ONLINE p2 - p0 - p1
	if(norm(v) + EPS < norm(w)) return -2; // ONLINE p0 - p1 - p2
	return 0; // ONLINE p0 - p1 - p2
}
bool isOrthogonal(Vector v1, Vector v2){
	double t = abs(dot(v1, v2));
	return t <= EPS;
}
bool isParallel(Vector v1, Vector v2){
	double t = abs(cross(v1, v2));
	return t <= EPS;
}
bool intersect(Segment s1, Segment s2){
	int t = ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second);
	int u = ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second);
	return (t == 0 || t == -1 || t == -4) && (u == 0 || u == -1 || u == -4);
}
Point getCrossPoint(Segment s1, Segment s2){
	assert(intersect(s1, s2));
	assert(!isParallel(s1.second - s1.first, s2.second - s2.first));
	Vector base = s2.second - s2.first;
	double d1 = abs(cross(base, s2.first - s1.first));
	double d2 = abs(cross(base, s2.first - s1.second));
	return s1.first + (s1.second - s1.first) * d1 / (d1 + d2);
}
double getDistancePL(Point p, Line l){
	return abs(cross(p - l.first, l.second - l.first)) / abs(l.second - l.first);
}
double getDistancePS(Point p, Segment s){
	if(dot(s.second - s.first, p - s.first) < 0.0) return abs(p - s.first);
	if(dot(s.first - s.second, p - s.second) < 0.0) return abs(p - s.second);
	return getDistancePL(p, Line(s));
}
double getDistanceSS(Segment s1, Segment s2){
	if(intersect(s1, s2)) return 0.0;
	return min({getDistancePS(s2.first, s1), getDistancePS(s2.second, s1), getDistancePS(s1.first, s2), getDistancePS(s1.second, s2)});
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	while(q--){
		double x[4], y[4];
		for(int i=0; i<4; ++i) cin >> x[i] >> y[i];
		Point p0(x[0], y[0]), p1(x[1], y[1]), p2(x[2], y[2]), p3(x[3], y[3]);
		cout << setprecision(14) << getDistanceSS(Segment(p0, p1), Segment(p2, p3)) << "\n";
	}
}
