#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <math.h>
#include <algorithm>
const double EPS = 1e-9;
using namespace std;
class vector {
public:
	double x, y;
	vector(double a, double  b) {
		x = a;
		y = b;
	};
	vector operator * (const vector &v)const {
		return vector(x*v.x, y* v.y);
	}
	vector operator * (double a) {
		return vector(x * a, y * a);
	}
	vector operator - (vector v) {
		return vector(x - v.x, y - v.y);
	}
	vector operator + (vector v) {
		return vector(x + v.x, y + v.y);
	}
};
inline double dot(vector v1, vector v2) {
	return v1.x*v2.x + v1.y*v2.y;
}
inline double squ(vector v) {
	return v.x*v.x + v.y*v.y;
}
inline double norm(vector v) {
	return sqrt(squ(v));
}
inline void print(vector v) {
	printf("%.10f %.10f\n", v.x, v.y);
}
inline vector pro(vector base, vector v, vector be) {
	double a = dot(base, v) / squ(base);
	vector v1 = base * a;
	return v1 + be;
}
inline vector ref(vector v, vector be) {
	return (v - be)*2 + be;
}
inline double cross(vector v1, vector v2) {
	return v1.x*v2.y - v1.y*v2.x;
}
inline int ccw(vector v1, vector v2, vector v3) {
	vector a = v2 - v1;
	vector b = v3 - v1;
	if (cross(a, b) < 0.0) return -1;
	else if (cross(a, b) > 0.0) return 1;
	else if (dot(a, b) < 0.0) return -2;
	else if (dot(a, b) > squ(v1)) return 2;
	else return 0;
}
inline int inter(vector v1, vector v2, vector v3, vector v4) {
	return (ccw(v1, v2, v3) * ccw(v1, v2, v4) <= 0) && (ccw(v3, v4, v1) * ccw(v3, v4, v2) <= 0);
}
inline double disPP(vector v1, vector v2) {
	return norm(v2 - v1);
}
inline double disLP(vector v1, vector v2, vector v3) {
	vector a = v2 - v1;
	vector b = v3 - v1;
	return fabs(cross(a, b) / norm(a));
}
inline double disSP(vector v1, vector v2, vector v3) {
	vector a = v2 - v1;
	vector b = v3 - v1;
	vector c = v1 - v2;
	vector d = v3 - v2;
	if (dot(a, b) < 0.0) return disPP(v1, v3);
	else if (dot(c, d) < 0.0) return disPP(v2, v3);
	else return disLP(v1, v2, v3);
}
inline double disSS(vector v1, vector v2, vector v3, vector v4) {
	if (inter(v1, v2, v3, v4)) return 0;
	double a = disSP(v1, v2, v3);
	double b = disSP(v1, v2, v4);
	double c = disSP(v3, v4, v1);
	double d = disSP(v3, v4, v2);
	return min(min(a, b), min(c, d));
}
/*int main() {
	//inter
	int n;
	double x0, x1, x2, x3, y0, y1, y2, y3;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		vector v1(x0,y0);
		vector v2(x1, y1);
		vector v3(x2, y2);
		vector v4(x3, y3);
		cout << inter(v1, v2, v3, v4) << endl;
	}
	return 0;
}
int main() {
	//clo
	int n;
	double x0, x1, x2, y0, y1, y2;
	cin >> x0 >> y0 >> x1 >> y1 >> n;
	vector v1(x0, y0);
	vector v1(x1, y1);
	for(int i = 0; i < n; i++) {
		cin >> x2 >> y2;
		vector v2(x2, y2);
		int ans = ccw(v0, v1, v2);
		 if(ans == -1) cout << "CLOCKWISE" << endl;
		 else if(ans == 1) cout << "COUNTER_CLOCKWISE" << endl;
		  else if(ans == -2)cout << "ONLINE_BACK" << endl;
		  else if(ans == 2)cout << "ONLINE_FRONT" << endl;
		else cout << "ON_SEGMENT" << endl;
	}
	return 0;
}*/
int main() {
	//distance
	int n;
	cin >> n;
	double x0, x1, x2, x3,y0,  y1, y2, y3;
	for (int i = 0; i < n; i++) {
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		vector v1(x0, y0);
		vector v2(x1, y1);
		vector v3(x2, y2);
		vector v4(x3, y3);
		printf("%.10f\n", disSS(v1, v2, v3, v4));
	}
	return 0;
}

Measured memory_bytes: 3272