#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define PII pair<int,int>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point
{
public:
	double x, y;
	Point(double X = 0, double Y = 0)
	{
		x = X;
		y = Y;
	}
	Point operator +(const Point &p)const { return Point(x + p.x, y + p.y); };
	Point operator -(const Point &p)const { return Point(x - p.x, y - p.y); };
	Point operator *(const double a)const { return Point(x*a, y*a); };
	Point operator /(const double a)const { return Point(x / a, y / a); };
	double norm()const { return x*x + y*y; };
	double length()const { return sqrt(norm()); };
	double dot(const Point &p)const { return x*p.x + y*p.y; };
	double cross(const Point &p)const { return x*p.y - y*p.x; };
	bool operator ==(const Point &p)const
	{
		return fabs(x - p.x)<EPS &&fabs(y - p.y)<EPS;
	}
	friend ostream& operator <<(ostream& os, const Point &p);
	int CCW(Point p1, Point p2)
	{
		Point p0(x, y);
		Point V1 = p1 - p0;
		Point V2 = p2 - p0;
		if (V1.cross(V2) > 0.0)return -1;
		else if (V1.cross(V2) < 0.0)return 1;
		else if (V1.dot(V2) < 0.0)return -2;
		else if (V1.norm() < V2.norm())return 2;
		return 0;
	}
};
typedef Point Vector;

ostream& operator <<(ostream& os, const Point &p)
{
	return os << "(" << p.x << "," << p.y << ")";
}

class Segment
{
public:
	Point p1, p2;
	Segment(double x1, double y1, double x2, double y2)
	{
		p1.x = x1;
		p1.y = y1;
		p2.x = x2;
		p2.y = y2;
	}
	double GetLength()
	{
		Point temp = p2 - p1;
		return temp.length();
	}
	double GetDistanceSeg(double X, double Y)
	{
		Point p(X, Y);
		Point a = p2 - p1;
		Point b = p - p1;
		Point c = p1 - p2;
		Point d = p - p2;
		if (a.dot(b) < 0.0)return b.length();
		if (c.dot(d) < 0.0)return d.length();
		return GetDistanceLine(X, Y);
	}
	double GetDistanceLine(double X, double Y)
	{
		Point t(X, Y);
		Point a = p2 - p1;
		Point b = t - p1;
		return abs(a.cross(b) / a.length());
	}
	bool IsIntersect(Segment &s)
	{
		int s1, s2;
		s1 = p1.CCW(p2, s.p1)*p1.CCW(p2, s.p2);
		s2 = s.p1.CCW(s.p2, p1)*s.p1.CCW(s.p2, p2);
		return s1 <= 0 && s2 <= 0;
	}
	bool IsOrthogonal(const Segment &s)
	{
		Vector t1 = p2 - p1;
		Vector t2 = s.p2 - s.p1;
		return equals(0.0, t1.dot(t2));
	}
	bool IsParallel(const Segment &s)
	{
		Vector t1 = p2 - p1;
		Vector t2 = s.p2 - s.p1;
		return equals(0.0, t1.cross(t2));
	}
	Point GetProjection(double X, double Y)const
	{
		Vector V = p2 - p1;
		Point P(X, Y);
		Point ret = V*(V.dot(P - p1) / V.norm());
		return ret + p1;
	}
	Point GetReflect(double X, double Y)
	{
		Point t(X, Y);
		Point Pro = GetProjection(X, Y);
		Vector dV = Pro - t;
		return t + dV*2.0;
	}
};
typedef Segment Line;

class Circle
{
public:
	Point c;
	double r;
	Circle(Point C = Point(), double R = 0)
	{
		c = C;
		r = R;
	}
};

int main()
{
	int q;
	cin >> q;
	REP(i, q)
	{
		int x0, y0, x1, y1, x2, y2, x3, y3;
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		Segment s1(x0, y0, x1, y1), s2(x2, y2, x3, y3);
		double ans;
		if (s1.IsIntersect(s2))ans = 0;
		else {ans = min({ s2.GetDistanceSeg(x0, y0), s2.GetDistanceSeg(x1, y1),s1.GetDistanceSeg(x2, y2), s1.GetDistanceSeg(x3, y3) });}
		cout << fixed << setprecision(10) << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3300