#include <bits/stdc++.h>
using namespace std;
/*
#ifndef ONLINE_JUDGE
	#include <boost/multiprecision/cpp_int.hpp>
	#include <boost/multiprecision/cpp_dec_float.hpp>
	using bll = boost::multiprecision::cpp_int;
	using bdouble = boost::multiprecision::cpp_dec_float_100;
#endif
*/
#ifdef LOCAL_DEV
	void debug_impl() { std::cerr << std::endl; }
	template<typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); }
	#define debug(...) { std::cerr << std::boolalpha << "(" << #__VA_ARGS__ << ") ="; debug_impl(__VA_ARGS__); std::cerr << std::noboolalpha; }
#else
	#define debug(...) {}
#endif
#ifdef LOCAL_TEST
	#define BOOST_STACKTRACE_USE_ADDR2LINE
	#define BOOST_STACKTRACE_ADDR2LINE_LOCATION /usr/local/opt/binutils/bin/addr2line
	#define _GNU_SOURCE
	#include <boost/stacktrace.hpp>
	template<typename T> class dvector : public std::vector<T> {
	public:
		dvector() : std::vector<T>() {}
		explicit dvector(size_t n, const T& value = T()) : std::vector<T>(n, value) {}
		dvector(const std::vector<T>& v) : std::vector<T>(v) {}
		dvector(const std::initializer_list<T> il) : std::vector<T>(il) {}
		dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {}
		dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {}
		T& operator[](size_t n) {
			try { return this->at(n); } catch (const std::exception& e) {
				std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n);
			}
		}
		const T& operator[](size_t n) const {
			try { return this->at(n); } catch (const std::exception& e) {
				std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n);
			}
		}
	};
	class dbool {
	private:
		bool boolvalue;
	public:
		dbool() : boolvalue(false) {}
		dbool(bool b) : boolvalue(b) {}
		dbool(const dbool &b) : boolvalue(b.boolvalue) {}
		operator bool&() { return boolvalue; }
		operator const bool&() const { return boolvalue; }
	};
	template<typename T> std::ostream& operator<<(std::ostream& s, const dvector<T>& v) {
		for (int i = 0, len = v.size(); i < len; ++i){ s << v[i]; if (i < len - 1) s << "\t"; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const dvector< dvector<T> >& vv) {
		for (int i = 0, len = vv.size(); i < len; ++i){ s << vv[i] << std::endl; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::multiset<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}"; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::map<T1, T2>& m) {
		s << "{" << std::endl; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << std::endl; } s << "}"; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::pair<T1, T2>& p) { 
		return s << "(" << p.first << ", " << p.second << ")"; }
	#define vector dvector
	#define bool dbool
	class SIGFPE_exception : std::exception {};
	class SIGSEGV_exception : std::exception {};
	void catch_SIGFPE(int e) { std::cerr << boost::stacktrace::stacktrace() << std::endl; throw SIGFPE_exception();	}
	void catch_SIGSEGV(int e) { std::cerr << boost::stacktrace::stacktrace() << std::endl; throw SIGSEGV_exception(); }
	signed convertedmain();
	signed main() { signal(SIGFPE, catch_SIGFPE); signal(SIGSEGV, catch_SIGSEGV); return convertedmain(); }
	#define main() convertedmain()
#endif
//#define int long long
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define rrep(i, n)   for(ll i=(n)-1; i>=0; --i)
#define rrepeq(i, n) for(ll i=(n)  ; i>=1; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline void pv(vector<T> &v) { for(ll i=0, N=v.size(); i<N; i++) std::cout << v[i] << " \n"[i==N-1]; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T> inline bool chmax(T &a, T b) { return a < b && (a = b, true); }
template<typename T> inline bool chmin(T &a, T b) { return a > b && (a = b, true); }

/*-----8<-----template-----8<-----*/

//点、ベクトル
class Point {
public:
	double x,y;
	Point(double x=0., double y=0.) : x(x), y(y) {}
	Point operator + (Point p) {return Point(x+p.x, y+p.y);}
	Point operator - (Point p) {return Point(x-p.x, y-p.y);}
	Point operator * (Point p) {return Point(x*p.x, y*p.y);}
	Point operator / (Point p) {return Point(x/p.x, y/p.y);}

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator < (const Point &p) const {
		return x!=p.x ? x<p.x : y<p.y;
	}
	bool operator == (const Point &p) const {
		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
	}
	
};
//using Vector = Point;
typedef Point Vector;

//線分、直線
class Segment {
public:
	Point p1,p2;
	Segment() {}
	Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};
//using Line = Segment;
typedef Segment Line;

//ベクトルの内積
double dot(Vector a, Vector b){
	return a.x*b.x + a.y*b.y;
}
//ベクトルの外積
double cross(Vector a, Vector b){
	return a.x*b.y - a.y*b.x;
}
double equals(double a,double b){ return fabs(a-b)<EPS; }
//直交判定
bool isOrthogonal(Vector a,Vector b){
	return equals(dot(a,b), 0.0);
}
bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
	return isOrthogonal(a1-a2, b1-b2);
}
bool isOrthogonal(Segment s1,Segment s2){
	return equals(dot(s1.p2-s1.p1, s2.p2-s2.p1), 0.0);
}
//平行判定
bool isParallel(Vector a,Vector b){
	return equals(cross(a,b), 0.0);
}
bool isParallel(Point a1,Point a2,Point b1,Point b2){
	return isParallel(a1-a2, b1-b2);
}
bool isParallel(Segment s1,Segment s2){
	return equals(cross(s1.p2-s1.p1, s2.p2-s2.p1), 0.0);
}
//射影
Point project(Segment s,Point p){
	Vector base = s.p2-s.p1;
	double r = dot(p-s.p1, base)/base.norm();
	Point rp(r,r);
	return base*rp + s.p1;
}
//反射
Point reflect(Segment s,Point p){
	Point x2(2.,2.);
	return p + (project(s,p)-p)*x2;
}

//p0,p1,p2が反時計回りになる
static const int COUNTER_CLOCKWISE = 1;
//p0,p1,p2が時計回りになる
static const int CLOCKWIZE = -1;
//p2,p0,p1がこの順で同一直線状にある
static const int ONLINE_BACK = 2;
//p0,p1,p2がこの順で同一直線状にある
static const int ONLINE_FRONT = -2;
//p2が線分p0p1上にある
static const int ON_SEGMENT = 0;
int ccw(Point p0, Point p1, Point p2){
	Vector a=p1-p0;
	Vector b=p2-p0;
	if(cross(a,b)>EPS)return COUNTER_CLOCKWISE;
	if(cross(a,b)<-EPS)return CLOCKWIZE;
	if(dot(a,b)<-EPS)return ONLINE_BACK;
	if(a.norm()<b.norm())return ONLINE_FRONT;
	return ON_SEGMENT;
}

//線分p1p2と線分p3p4の交差判定
//端点が他方の線分上にある場合、線分二つが平行に重なる場合も交差しているとみなす
bool intersect(Point p1, Point p2, Point p3, Point p4){
	return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 && ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}
bool intersect(Segment s1, Segment s2){
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

//二点間の距離
double getDistance(Point a,Point b){
	return (a-b).abs();
}
//点と直線の距離
double getDistanceLP(Line l,Point p){
	return fabs(cross(l.p2-l.p1, p-l.p1)) / (l.p2-l.p1).abs();
}
//点と線分の距離
double getDistanceSP(Segment s,Point p){
	if(dot(s.p2-s.p1, p-s.p1)<0.)return (p-s.p1).abs();
	if(dot(s.p1-s.p2, p-s.p2)<0.)return (p-s.p2).abs();
	return getDistanceLP(s,p);
}
//線分と線分の距離
double getDistance(Segment s1,Segment s2){
	if(intersect(s1,s2))return 0.;
	return min({getDistanceSP(s1,s2.p1), getDistanceSP(s1,s2.p2), getDistanceSP(s2,s1.p1), getDistanceSP(s2,s1.p2)});
}

//線分s1と線分s2の交点
Point getCrossPoint(Segment s1, Segment s2){
	Vector base = s2.p2-s2.p1;
	double d1=fabs(cross(base, s1.p1-s2.p1));
	double d2=fabs(cross(base, s1.p2-s2.p1));
	double t=d1/(d1+d2);
	return s1.p1+(s1.p2-s1.p1)*t;
}

//円
class Circle {
public:
	Point c;
	double r;
	Circle(Point c=Point(), double r=0.) : c(c), r(r) {}
};
//円cと線分lの交点二つ
pair<Point,Point> getCrossPoints(Circle c, Line l){
	//交点が存在するか
	assert(getDistanceLP(l,c.c)<c.r);
	Vector pr=project(l, c.c);
	Vector e=(l.p2-l.p1)/(l.p2-l.p1).abs();
	double base=sqrt(c.r*c.r-(pr-c.c).norm());
	return {pr+e*base, pr-e*base};
}

typedef vector<Point> Polygon;
//多角形gと点pの内包関係を返す
static const int INSIDE = 2;
static const int ONLINE = 1;
static const int OUTSIDE = 0;
ll contains(Polygon &g, Point p){
	ll n=g.size();
	bool x=false;
	for(ll i=0; i<n; i++){
		Point a=g[i]-p, b=g[(i+1)%n]-p;
		if(fabs(cross(a,b)) < EPS && dot(a,b) < EPS) return ONLINE;
		if(a.y > b.y) swap(a,b);
		if(a.y < EPS && EPS < b.y && cross(a,b) > EPS) x=!x;
	}
	return (x ? INSIDE : OUTSIDE);
}

//点の集合sに対する凸包を返す
Polygon andrewScan(Polygon s){
	Polygon u,l;
	if(s.size()<3) return s;
	sort(s.begin(), s.end());
	u.push_back(s[0]);
	u.push_back(s[1]);
	l.push_back(s[s.size()-1]);
	l.push_back(s[s.size()-2]);

	for(ll i=2; i<(ll)s.size(); i++){
		for(ll n=u.size(); n>=2 && ccw(u[n-2],u[n-1],s[i])!=CLOCKWIZE; n--){
			u.pop_back();
		}
		u.push_back(s[i]);
	}
	for(ll i=s.size()-3; i>=0; i--){
		for(ll n=l.size(); n>=2 && ccw(l[n-2],l[n-1],s[i])!=CLOCKWIZE; n--){
			l.pop_back();
		}
		l.push_back(s[i]);
	}

	reverse(l.begin(), l.end());
	for(ll i=u.size()-2; i>=1; i--)l.push_back(u[i]);

	return l;
}


//線分の集合sの交点の数を返す
class EndPoint {
public:
	Point pnt;
	ll seg,st; //入力線分のID, 端点の種類
	EndPoint() {}
	EndPoint(Point pnt, ll seg, ll st) : pnt(pnt), seg(seg), st(st) {}

	bool operator < (const EndPoint &ep) const {
		if(pnt.y == ep.pnt.y) return st < ep.st;
		return pnt.y < ep.pnt.y;
	}
};
ll manhattanIntersection(vector<Segment> &S){
	static const int BOTTOM = 0;
	static const int LEFT = 1;
	static const int RIGHT = 2;
	static const int TOP = 3;
	ll n=S.size();
	vector<EndPoint> EP(2*n);
	for(ll i=0,k=0; i<n; i++){
		if(S[i].p1.y==S[i].p2.y){
			if(S[i].p1.x>S[i].p2.x) swap(S[i].p1, S[i].p2);
		}else if(S[i].p1.y > S[i].p2.y){
			swap(S[i].p1, S[i].p2);
		}

		if(S[i].p1.y==S[i].p2.y){
			EP[k++]=EndPoint(S[i].p1, i, LEFT);
			EP[k++]=EndPoint(S[i].p2, i, RIGHT);
		}else{
			EP[k++]=EndPoint(S[i].p1, i, BOTTOM);
			EP[k++]=EndPoint(S[i].p2, i, TOP);
		}
	}

	sort(EP.begin(), EP.end());

	set<ll> BT;
	BT.insert(INF);
	ll cnt=0;
	for(ll i=0; i<2*n; i++){
		if(EP[i].st==TOP){
			BT.erase(EP[i].pnt.x);
		}else if(EP[i].st==BOTTOM){
			BT.erase(EP[i].pnt.x);
		}else if(EP[i].st==LEFT){
			auto b=BT.lower_bound(S[EP[i].seg].p1.x);
			auto e=BT.upper_bound(S[EP[i].seg].p2.x);
			cnt+=distance(b,e);
		}
	}
	return cnt;
}


/*-----8<-----library-----8<-----*/

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=ja
void CGL_2_A(){
	ll N;
	cin>>N;
	vector<ll> ans(N,0);
	rep(i,N){
		double x0,y0,x1,y1,x2,y2,x3,y3;
		cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
		Point p0(x0,y0),p1(x1,y1),p2(x2,y2),p3(x3,y3);
		ll t=0;
		if(isOrthogonal(p0,p1,p2,p3)){
			t=1;
		}else if(isParallel(p0,p1,p2,p3)){
			t=2;
		}
		ans[i]=t;
	}
	rep(i,N)p(ans[i]);
}

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A&lang=ja
void CGL_1_A(){
	double x0,y0,x1,y1;
	cin>>x0>>y0>>x1>>y1;
	Line l(Point(x0,y0),Point(x1,y1));
	ll Q;
	cin>>Q;
	vector<Point> ans(Q,0);
	rep(i,Q){
		double xq,yq;
		cin>>xq>>yq;
		Point po(xq,yq);
		Point t=project(l,po);
		ans[i]=t;
	}
	cout.setf(ios::fixed), cout.precision(20);
	rep(i,Q){
		cout<<ans[i].x<<' '<<ans[i].y<<'\n';
	}
}

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B&lang=ja
void CGL_1_B(){
	double x0,y0,x1,y1;
	cin>>x0>>y0>>x1>>y1;
	Line l(Point(x0,y0),Point(x1,y1));
	ll Q;
	cin>>Q;
	vector<Point> ans(Q,0);
	rep(i,Q){
		double xq,yq;
		cin>>xq>>yq;
		Point po(xq,yq);
		Point t=reflect(l,po);
		ans[i]=t;
	}
	cout.setf(ios::fixed), cout.precision(20);
	rep(i,Q){
		cout<<ans[i].x<<' '<<ans[i].y<<'\n';
	}
}

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D&lang=ja
void CGL_2_D(){
	ll Q;
	cin>>Q;
	vector<double> ans(Q,0);
	rep(i,Q){
		double x0,y0,x1,y1,x2,y2,x3,y3;
		cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
		Segment s0(Point(x0,y0),Point(x1,y1)), s1(Point(x2,y2),Point(x3,y3));
		double t=getDistance(s0,s1);
		ans[i]=t;
	}
	cout.setf(ios::fixed), cout.precision(20);
	rep(i,Q)p(ans[i]);
}

signed main() {
	//CGL_2_A();
	//CGL_1_A();
	//CGL_1_B();
	CGL_2_D();

	return 0;
}



Measured memory_bytes: 3312