#include <stdio.h>
#include <math.h>
const double eps=1e-9;
double ABS(double n){return n>=0?n:-n;}
double min(double a,double b){return a>b?b:a;}
double max(double a,double b){return a>b?a:b;}
bool same(double a,double b){return ABS(a-b)<eps;}
struct point{
	double x;
	double y;
	point(){}
	point(double a,double b){x=a;y=b;}
	point operator +(const point &a){return point(x+a.x,y+a.y);}
	point operator -(const point &a){return point(x-a.x,y-a.y);}
	point operator *(const double &a){return point(x*a,y*a);}
	point operator /(const double &a){return point(x/a,y/a);}
	void operator =(const point &a){x=a.x;y=a.y;}
	void operator +=(const point &a){x+=a.x;y+=a.y;}
	void operator -=(const point &a){x-=a.x;y-=a.y;}
	void operator *=(const double &a){x*=a;y*=a;}
	void operator /=(const double &a){x/=a;y/=a;}
	bool operator <(const point &a){return x<a.x||(same(x,a.x)&&y<a.y);}
	bool operator ==(const point &a){return same(x,a.x)&&same(y,a.y);}
	double length(){return sqrt(x*x+y*y);}
	void in(){scanf("%lf%lf",&x,&y);}
	void out(){printf("%.20lf %.20lf\n",x,y);}
};
struct segment{
	point a;
	point b;
	segment(){}
	segment(point x,point y){a=x;b=y;}
};
struct line{
	double A;
	double B;
	double C;
	line(){}
	line(double a,double b,double c){A=a;B=b;C=c;}
	line(point a,point b){
		A=a.y-b.y;
		B=b.x-a.x;
		C=A*a.x+B*a.y;
	}
	line(double a,double b,point p){
		A=a;
		B=b;
		C=A*p.x+B*p.y;
	}
	line(segment s){
		A=s.a.y-s.b.y;
		B=s.b.x-s.a.x;
		C=A*s.a.x+B*s.a.y;
	}
};
double distance(point a,point b){return (a-b).length();}
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-b.x*a.y;}
//angle only returns positive value
double angle(point a,point b){return acos(dot(a,b)/(a.length()*b.length()));}
double area(point a,point b,point c){return ABS(cross(b-a,c-a));}
double distance(point a,line b){return (b.A*a.x+b.B*a.y-b.C)/sqrt(b.A*b.A+b.B*b.B);}
bool between(point a,point b,point c){
	if((a.x-b.x<=eps&&b.x-c.x<=eps)||(eps>=b.x-a.x&&eps>=c.x-b.x))
	if((a.y-b.y<=eps&&b.y-c.y<=eps)||(eps>=b.y-a.y&&eps>=c.y-b.y))
	return true;
	return false;
}
point intersect(line a,line b){
	double x,y,det;
	x=(a.C*b.B-b.C*a.B);
	y=(a.A*b.C-b.A*a.C);
	det=(a.A*b.B-b.A*a.B);
	return point(x,y)/det;
}
bool parallel(line a,line b){return same(a.A*b.B,b.A*a.B);}
double distance(line a,line b){}
double distance(point p,segment s){
	line l(s);
	point a(intersect(line(l.B,-l.A,l.B*p.x-l.A*p.y),l));
	if(between(s.a,a,s.b))return distance(p,a);
	else return min(distance(p,s.a),distance(p,s.b));
}
double distance(segment a,segment b){
	point l(a.a),lm,rm,r(a.b);
	for(int i=0;i<100;i++){
		lm=(l*2+r)/3;
		rm=(l+r*2)/3;
		if(distance(lm,b)>distance(rm,b))l=lm;
		else r=rm;
	}
	return distance(l,b);
}
bool same(line a,line b){return distance(a,b)<=eps;}
bool vertical(line a,line b){return ABS(a.A*b.A+a.B*b.B)<=eps;}
bool hasintersect(segment a,segment b){
	line l(a),r(b);
	if(parallel(l,r)){
		if(same(l,r))return between(a.a,b.a,a.b)||between(a.a,b.b,a.b)||between(b.a,a.a,b.b)||between(b.a,a.b,b.b);
		else return false;
	}
	else{
		point p(intersect(l,r));
		return between(a.a,p,a.b)&&between(b.a,p,b.b);
	}
}
point intersect(segment a,segment b){return intersect(line(a),line(b));}
point projection(point a,line b){return intersect(line(b.B,-b.A,a),b);}
point reflection(point a,line b){return projection(a,b)*2-a;}
bool online(point p,line l){return ABS(l.A*p.x+l.B*p.y-l.C)<eps;}
bool onseg(point p,segment s){return online(p,line(s))&&between(s.a,p,s.b);}
void solve(){
	segment a,b;
	point x,y;
	x.in();
	y.in();
	a=segment(x,y);
	x.in();
	y.in();
	b=segment(x,y);
	printf("%.20lf\n",distance(a,b));
	return ;
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--)solve();
}



Measured memory_bytes: 2760