Problem: For given two segments s1 and s2, print the distance between them.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.

Input

The entire input looks like:


q (the number of queries)
1st query
2nd query
...
qth query


Each query consists of integer coordinates of end points of s1 and s2 in the following format:


xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3


Output

For each query, print the distance. The output values should be in a decimal fraction with an error less than 0.00000001.

Example

Input

3
0 0 1 0 0 1 1 1
0 0 1 0 2 1 1 2
-1 0 1 0 0 1 0 -1


Output

1.0000000000
1.4142135624
0.0000000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define ll  long long
//#define int long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
const int N=2e5+10;
const int mod=998244353;
using namespace std;


const double eps=1e-8;
inline int sgn(double x){return x<-eps?-1:(x>eps?1:0);}
inline double pf(double x){return x*x;}
struct Point
{
   double x,y;
   Point(){}
   Point(double x,double y):x(x),y(y){}
   Point(pair<double,double> p):x(p.first),y(p.second){}
   bool operator == (const Point& p)const {return sgn(x-p.x)==0&&sgn(y-p.y)==0;}
   bool operator != (const Point& p)const {return sgn(x-p.x)!=0||sgn(y-p.y)!=0;}
   inline double length()const {return sqrt(pf(x)+pf(y));}
   inline double angle()const{return atan2(y,x);}
};
typedef Point Vector;
Vector operator + (Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator - (Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator * (Vector a,double mul){return Vector(a.x*mul,a.y*mul);}
Vector operator / (Vector a,double div){return Vector(a.x/div,a.y/div);}
inline double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
inline double cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
inline double dis(Vector a,Vector b){return sqrt(pf(a.x-b.x)+pf(a.y-b.y));}
inline double angle(Vector a,Vector b){return acos(dot(a,b)/a.length()/b.length());}
Vector rot(Vector a,double rad){return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));}//ni shi zhen
Vector unit(Vector v){return v/v.length();}// 单位向量
Vector normal(Vector a){return Vector(-a.y,a.x);} // 法向量
struct Line
{
   Point p1,p2;
   Vector v;
   Line(){}
   Line(Point p1,Point p2,Vector v): p1(p1),p2(p2),v(v){}
};
double x[5],y[5];
int jiao()
{
	 if(max(x[1],x[2])<min(x[3],x[4])||min(x[1],x[2])>max(x[3],x[4])||max(y[1],y[2])<min(y[3],y[4])||min(y[1],y[2])>max(y[3],y[4])) 
   	  {
   	  	 return 0;
   	  }	
   	  double p1=cross(Point(x[3]-x[1],y[3]-y[1]),Point(x[2]-x[1],y[2]-y[1])); 
   	  double p2=cross(Point(x[4]-x[1],y[4]-y[1]),Point(x[2]-x[1],y[2]-y[1]));
   	  double p3=cross(Point(x[1]-x[3],y[1]-y[3]),Point(x[4]-x[3],y[4]-y[3]));  
   	  double p4=cross(Point(x[2]-x[3],y[2]-y[3]),Point(x[4]-x[3],y[4]-y[3]));   
   	  if(p1*p2<=0&&p3*p4<=0) return 1;
   	  return 0;
}
double dispointline(Point p,Line l)
{
	return fabs(cross(p-l.p1,l.v)/l.v.length());
}
double dispointseg(Point p,Line s)
{
	double ans=min(dis(p,s.p1),dis(p,s.p2));
	if(dot(p-s.p1,s.p2-s.p1)<-eps||dot(p-s.p2,s.p1-s.p2)<-eps) return ans;
	return dispointline(p,s);
}
int32_t main()
{
   //ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
   int q; scanf("%d",&q);
   while(q--)
   {
   	  for(int i=1;i<=4;i++) scanf("%lf%lf",&x[i],&y[i]);
   	  if(jiao()) {puts("0"); continue; }
   	  Line l1=Line(Point(x[1],y[1]),Point(x[2],y[2]),Vector(x[2]-x[1],y[2]-y[1]));
   	  Line l2=Line(Point(x[3],y[3]),Point(x[4],y[4]),Vector(x[4]-x[3],y[4]-y[3]));
   	  double ans=min(dispointseg(l1.p1,l2),dispointseg(l1.p2,l2));
   	  ans=min(ans,min(dispointseg(l2.p1,l1),dispointseg(l2.p2,l1)));
   	  printf("%.10f\n",ans);
   }
return 0;
}
/*

*/