#include<bits/stdc++.h>
#define REP(i,first,last) for(int i=first;i<=last;++i)
#define DOW(i,first,last) for(int i=first;i>=last;--i)
using namespace std;
inline int Read()
{
	int x(0),f(1);
	char c(getchar());
	while(c<'0'||'9'<c)
	{
		if(c=='-')
		{
			f=-1;
		}
		c=getchar();
	}
	while('0'<=c&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return f*x;
}
void Write(int x)
{
	if(x<0)
	{
		printf("-");
		x=-x;
	}
	if(9<x)
	{
		Write(x/10);
	}
	putchar(x%10+'0');
}
inline void Writeln(int x)
{
	Write(x);
	puts("");
}
struct Point
{
	double x,y;
	Point(double fx=0,double fy=0)
	{
		x=fx;
		y=fy;
	}
	void Read()
	{
		scanf("%lf%lf",&x,&y);
	}
	void Write(int len=2)
	{
		printf("%.9lf %.9lf",x,y);
	}
	double operator ^(Point const b)const
	{
		return x*b.x+y*b.y;
	}
	double operator |(Point const b)const
	{
		return x*b.y-b.x*y;
	}
	double operator ==(Point const b)const
	{
		return sqrt((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y));
	}
	Point operator *(double const b)const
	{
		return Point(x*b,y*b);
	}
	Point operator +(Point const b)const
	{
		return Point(x+b.x,y+b.y);
	}
	Point operator -(Point const b)const
	{
		return Point(x-b.x,y-b.y);
	}
};
Point Symmetrical(Point a,Point m=Point(0,0))
{
	return Point(m.x*2-a.x,m.y*2-a.y);
}
/**
 *      /
 *   a /
 *    m
 *   / b
 *  /
 * return b;
 */
struct Vector
{
	Point a,b;
	Vector(Point f=Point(0,0),Point e=Point(0,0))
	{
		a=f;
		b=e;
	}
	double operator ^(Vector const c)const
	{
		return (a.x-b.x)*(c.a.x-c.b.x)+(c.a.y-c.b.y)*(a.y-b.y);
	}
	double operator |(Vector const c)const
	{
		return (a.x-b.x)*(c.a.y-c.b.y)-(c.a.x-c.b.x)*(a.y-b.y);
	}
};
Point ProjectivePoint(Point a,Vector b)
{
	double c=Vector(b.a,a)^Vector(b.a,b.b);
	c/=(b.a==b.b)*(b.a==b.b);
	return (b.b-b.a)*c+b.a;
}
/**
 *     *
 *     |
 *     |
 * *---m-----*
 *
 *         *
 *         |
 *         |
 * *----*  m
 * return m;
 */
double PointToVector(Point a,Vector b)
{
	Point c=ProjectivePoint(a,b);
	if(
		(
			(b.a.x<=c.x)==(c.x<=b.b.x)
		)
		&&
		(
			(b.a.y<=c.y)==(c.y<=b.b.y)
		)
	)
	{
		return a==c;
	}
	return min(a==b.a,a==b.b);
}
bool InRectangle(Point a,Point b,Point c)
{
	return
	min(b.x,c.x)<=a.x&&a.x<=max(b.x,c.x)
	&&
	min(b.y,c.y)<=a.y&&a.y<=max(b.y,c.y);
}
/**
 *   a
 *  b---*
 *  |   |
 *  *---c
 *  return 0;
 *
 *  b---*
 *  |a  |
 *  *---c
 *  return 1;
 */
bool RectangleIntersection(Point a0,Point a1,Point b0,Point b1)
{
	int zx=fabs(a0.x+a1.x-b0.x-b1.x);
	int zy=fabs(a0.y+a1.y-b0.y-b1.y);
	int x=fabs(a0.x-a1.x)+fabs(b0.x-b1.x);
	int y=fabs(a0.y-a1.y)+fabs(b0.y-b1.y);
	if(zx<=x&&zy<=y)
	{
		return 1;
	}
	return 0;
}
/**
 *  *---*
 *  |   |
 *  *---*
 *
 *    *--*
 *    |  |
 *    |  |
 *    *--*
 * return 0;
 *
 *  *---*
 *  | *-+*
 *  *-+-*|
 *    |  |
 *    *--*
 * return 1;
 */
bool Intersect(Vector a,Vector b)
{
	double a_aa=a|Vector(a.a,b.a);
	double a_ab=a|Vector(a.a,b.b);
	double b_aa=b|Vector(b.a,a.a);
	double b_ab=b|Vector(b.a,a.b);
	if((a_aa==0||a_ab==0||((a_aa<0)^(a_ab<0)))&&(b_aa==0||b_ab==0||((b_aa<0)^(b_ab<0))))
	{
		return RectangleIntersection(a.a,a.b,b.a,b.b);
	}
	return 0;
}
/**
 *      *
 *     /
 *    /*
 *   /  \
 *  /    \
 * *      *
 * return 0;
 *
 *      *
 *  *  /
 *   \/
 *   /\
 *  /  \
 * *    *
 * return 1;
 */
Point QueryIntersect(Vector a,Vector b)
{
	Vector u(a.a,b.a);
	Vector v(b.a,b.b);
	Vector w(a.a,a.b);
	double c=(w|u)/(v|w);
	return Point(b.a.x+(b.b.x-b.a.x)*c,b.a.y+(b.b.y-b.a.y)*c);
}
/**
 *        *
 * *     /
 *  \   /
 *   \ /
 *    m
 *   / \
 *  *   \
 *       *
 * return m;
 */
Point p0,p1,p2,p3;
void Work()
{
	p0.Read();
	p1.Read();
	p2.Read();
	p3.Read();
	if(Intersect(Vector(p0,p1),Vector(p2,p3)))
	{
		printf("%.9lf\n",0.0);
		return;
	}
	double answer=
	min
	(
		min(PointToVector(p0,Vector(p2,p3)),PointToVector(p1,Vector(p2,p3))),
		min(PointToVector(p2,Vector(p0,p1)),PointToVector(p3,Vector(p0,p1)))
	);
	printf("%.9lf\n",answer);
}
int main()
{
	int q;
	scanf("%d",&q);
	REP(i,1,q)
	{
		Work();
	}
	return 0;
}


Measured memory_bytes: 3248