//Distance
//#include<bits/stdc++.h>
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
//#include<random>
#include<cstdlib>
#include<ctime>
#include<fstream>
#include<map>
#include<stack>
#include<queue>
#define FAST ios::sync_with_stdio(false)
#define DEV_RND ((int)rand()*RAND_MAX+rand())
#define RND(L,R) (DEV_RND%((R)-(L)+1)+(L))
//#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<n;++i)
#define repn(i,a,n,t) for(int i=a;i<n;i+=t)
#define per(i,n,a) for(int i=n-1;i>=a;--i)
#define pern(i,n,a,t) for(int i=n-1;i>=a;i-=t)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define li inline
#define re register
using namespace std;
//typedef uniform_int_distribution<int> RNDI;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef double db;
typedef long long ll;
typedef long double ld;
const int maxn = 1e5+5;
const int maxm = 100000+5;
const int inf=0x3f3f3f3f;
const double eps = 1e-9;
const double pi=acos(-1);
const int mod = 1e9+7;
//int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//li int f(int x){return x==par[x]?par[x]:par[x]=f(par[x]);}
//mt19937 eng(time(0));
li ll lowbit(ll x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
//li int RND(int L,int R){RNDI rnd(L,R);return rnd(eng);}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
li ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
li ll qmul(ll a,ll b,ll MOD=mod){return (a*b-(ll)((long double)a/MOD*b)*MOD+MOD)%MOD;}
li ll Qpow(ll a,ll b,ll MOD){ll res=1;while(b>0){if(b&1) res=qmul(res,a,MOD);a=qmul(a,a,MOD);b>>=1;}return res;}
li ll inv(ll x,ll p){return qpow(x,p-2,p);}
li ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
li void debug(){ofstream fout("C:\\Users\\Administrator\\Desktop\\in.txt");fout.close();}
namespace IO
{
	li int read()
	{
		int x=0,sign=1;char c=getchar();
		while(c>'9'||c<'0') {if(c=='-') sign=-1;c=getchar();}
		while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();
		return x*sign;
	}
	template<typename T>
	li void write(T x,char t='\n')
	{
		if(x<0){x=-x;putchar('-');};
		static int sta[25];int top=0;
		do{sta[top++]=x%10,x/=10;}while(x);
		while(top) putchar(sta[--top]+'0');
		putchar(t);
	}
}
using namespace IO;
/*-------------head-------------*/
li int sign(db k){return k<-eps?-1:k>eps;}
li int cmp(db a,db b){return sign(a-b);}
li bool inmid(db l,db m,db r){return sign(l-m)*sign(r-m)<=0;}
//点类 
struct P
{
	db x,y;
	P(){}
	P(db _x,db _y):x(_x),y(_y){}
	P operator + (const P& a) const {return (P){x+a.x,y+a.y};}
	P operator - (const P& a) const {return (P){x-a.x,y-a.y};}
	P operator * (db a) const {return (P){x*a,y*a};}
	P operator / (db a) const {return (P){x/a,y/a};}
	bool operator < (const P& a)const
	{return cmp(x,a.x)?cmp(x,a.x)==-1:cmp(y,a.y)==-1;}
	bool operator == (const P& a)const
	{return cmp(x,a.x)==0&&cmp(y,a.y)==0;}
	db alpha(){return atan2(y,x);}
	db abs2(){return x*x+y*y;}
	db abs(){return sqrt(abs2());}
	db disTo(P a){return (*this-a).abs();}
	db dot(P a){return x*a.x+y*a.y;}
	db det(P a){return x*a.y-y*a.x;}
	P unit(){return *this/abs();}
	P rot(db an){return (P){x*cos(an)-y*sin(an),x*sin(an)+y*cos(an)};}
	P rot90(){return (P){-y,x};}
	int quad() const {return sign(y)==1||(sign(y)==0&&sign(x)>=0);}
	void read(){db _x,_y;scanf("%lf%lf",&_x,&_y);x=_x;y=_y;}
	void write(){printf("%.10f %.10f\n",x,y);}
};
bool angcmp(P a,P b){return a.quad()!=b.quad()?a.quad()<b.quad():sign(a.det(b))==-1;}
bool inmid(P a,P m,P b){return inmid(a.x,m.x,b.x)&&inmid(a.y,m.y,b.y);}
db rad(P a,P b){return atan2l(a.det(b),a.dot(b));}
db cro(P q,P p1,P p2){return (p1.x-q.x)*(p2.y-q.y)-(p1.y-q.y)*(p2.x-q.x);}
int croOp(P q,P p1,P p2){return sign(cro(q,p1,p2));}
//线段相交
bool intersect(db l1,db r1,db l2,db r2)
{
	if(l1>r1)swap(l1,r1);if(l2>r2)swap(l2,r2);
	return !(cmp(r1,l2)==-1||cmp(r2,l1)==-1);
}
bool isSS(P p1,P p2,P q1,P q2)
{
	return intersect(p1.x,p2.x,q1.x,q2.x)&&intersect(p1.y,p2.y,q1.y,q2.y)
	&&croOp(p1,p2,q1)*croOp(p1,p2,q2)<=0
	&&croOp(q1,q2,p1)*croOp(q1,q2,p2)<=0;
}
bool isSS_strict(P p1,P p2,P q1,P q2)
{
	return croOp(p1,p2,q1)*croOp(p1,p2,q2)<0
	&&croOp(q1,q2,p1)*croOp(q1,q2,p2)<0;
}
//投影 
P proj(P p1,P p2,P q)
{
	P dir=p2-p1;
	return p1+dir*(dir.dot(q-p1)/dir.abs2());
}
//最近点 
db nearest(P p1,P p2,P q)
{
	P h=proj(p1,p2,q);
	return inmid(p1,h,p2)?q.disTo(h):min(p1.disTo(q),p2.disTo(q));
}
//线段距离 
db disSS(P p1,P p2,P q1,P q2)
{
	if(isSS(p1,p2,q1,q2)) return 0;
	return min(min(nearest(p1,p2,q1),nearest(p1,p2,q2)),min(nearest(q1,q2,p1),nearest(q1,q2,p2)));
}
P p1,p2,q1,q2;
li void solve()
{
	p1.read(),p2.read();
	q1.read(),q2.read();
	db dis=disSS(p1,p2,q1,q2);
	printf("%.10f\n",dis);
	//puts("");
}
int main()
{
	//srand(time(0));debug();
	//clock_t start_time=clock();
	//freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
	for(int QwQ=read();QwQ;QwQ--) solve();
	//while(~scanf("%d",&n)) solve();
	//cerr<<"Time:"<<clock()-start_time<<"ms\n";
	return 0;
} 


Measured memory_bytes: 3236