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

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define rep(x, a, b) for(int x = (a); x <= (b); ++ x)
#define per(x, a, b) for(int x = (a); x >= (b); -- x)
#define rop(x, a, b) for(int x = (a); x < (b); ++ x)
#define por(x, a, b) for(int x = (a); x > (b); -- x) 

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int unt;
typedef double db;
typedef pair <int, int> pii;
typedef vector <int> vi;

const db eps  = 1e-8;
const db _PI  = 3.1415926535897932384;
const db _E   = 2.7182818284590452354;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3fll;

int dcmp(db x) {
	if(x > eps) return 1;
	if(x < -eps) return -1;
	return 0;
}

int dcmp(db x, db y) {
	return dcmp(x - y);
}

struct Point {
	db x, y;
	Point(db _x = 0, db _y = 0) : x(_x), y(_y) {}
	void print() { printf("%.10f %.10f", x, y); }
};
struct Line {
	Point p1, p2;
	Line() {};
	Line(Point _p1, Point _p2) : p1(_p1), p2(_p2) {};
};

typedef Point Vector;
typedef Line Segment;

// CCW
const int CCW_COUNTER_CLOCKWISE = 1;
const int CCW_CLOCKWISE = -1;
const int CCW_ONLINE_FRONT = -2;
const int CCW_ONLINE_BACK = 2;
const int CCW_ON_SEGMENT = 0;

Vector operator + (Vector a, Vector b) {
	return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (Vector a, Vector b) {
	return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (Vector a, db b) {
	return Vector(a.x * b, a.y * b);
}
Vector operator / (Vector a, db b) {
	return Vector(a.x / b, a.y / b);
}
db operator * (Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}
db operator ^ (Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}
db dis(Point a, Point b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
db dis2(Point a, Point b) {
	return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
db dis(Vector a) {
	return sqrt(a.x * a.x + a.y * a.y);
}
db dis2(Vector a) {
	return a.x * a.x + a.y * a.y;
}
Point Project(Line L, Point p) {
	Vector Base = L.p2 - L.p1;
	db len = Base * (p - L.p1);
	return L.p1 + Base * (len / dis2(L.p1, L.p2));
}
Point Reflect(Line L, Point p) {
	return p + (Project(L, p) - p) * 2.0;
}

int ccw(Point p0, Point p1, Point p2) {
	Vector p01 = p1 - p0, p02 = p2 - p0;
	if(dcmp(p01 ^ p02) == 1) return CCW_COUNTER_CLOCKWISE; // 顺时针 
	if(dcmp(p01 ^ p02) == -1) return CCW_CLOCKWISE;        // 逆时针 
	if(dcmp(p01 * p02) == -1) return CCW_ONLINE_BACK;
	if(dcmp(dis2(p01), dis2(p02)) == -1) return CCW_ONLINE_FRONT;
	return CCW_ON_SEGMENT;
}

bool isOrthogonal(Vector a, Vector b) {
	return dcmp(a * b) == 0;
}
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
	return isOrthogonal(a2 - a1, b2 - b1);
}
bool isOrthogonal(Line a, Line b) {
	return isOrthogonal(a.p2 - a.p1, b.p2 - b.p1);
}
bool isParallel(Vector a, Vector b) {
	return dcmp(a ^ b) == 0;
}
bool isParallel(Point a1, Point a2, Point b1, Point b2) {
	return isParallel(a2 - a1, b2 - b1);
}
bool isParallel(Line a, Line b) {
	return isParallel(a.p2 - a.p1, b.p2 - b.p1);
}
bool IntersectSS(Point a1, Point a2, Point b1, Point b2) {
	return ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 && ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0;
}
bool IntersectSS(Segment a, Segment b) {
	return IntersectSS(a.p1, a.p2, b.p1, b.p2);
}
Point getCrossPointSS(Segment a, Segment b) {
	Vector Base = b.p2 - b.p1;
	db S1 = fabs(Base ^ (a.p1 - b.p1));
	db S2 = fabs(Base ^ (a.p2 - b.p1));
	return a.p1 + (a.p2 - a.p1) * (S1 / (S1 + S2));
}
//Point getCrossPointLL(Line a, Line b) {
//	db S1 = (b.p2 - b.p1) ^ (a.p2 - a.p1);
//	db S2 = (b.p2 - b.p1) ^ (b.p2 - a.p1);
//	if(dcmp(S1) <= 0 && dcmp(S2) <= 0) return a.p1;
//	return a.p1 + (a.p2 - a.p1) * (S2 / S1); //抄的别人代码，然而并不懂为啥/kel 
//}
db disLP(Line a, Point p) {
	return fabs(((a.p2 - a.p1) ^ (p - a.p1)) / dis(a.p1, a.p2));
}
db disSP(Segment a, Point p) {
	if(dcmp((a.p2 - a.p1) * (p - a.p1)) == -1) return dis(a.p1, p);
	if(dcmp((a.p1 - a.p2) * (p - a.p2)) == -1) return dis(a.p2, p);
	return disLP(a, p);
}
db disSS(Segment a, Segment b) {
	if(IntersectSS(a, b)) return 0;
	return min({disSP(b, a.p1), disSP(b, a.p2), disSP(a, b.p1), disSP(a, b.p2)});
}

int main() {
	int q; scanf("%d", &q);
	rep(i, 1, q) {
		Segment a, b;
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &a.p1.x, &a.p1.y, &a.p2.x, &a.p2.y, &b.p1.x, &b.p1.y, &b.p2.x, &b.p2.y);
		printf("%.10f\n", disSS(a, b));
	}
	return 0;
}


Measured memory_bytes: 3252