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>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):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*(double k){return Point(x*k,y*k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{
    return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
  }
  double dot(Point p){return x*p.x+y*p.y;}
  double det(Point p){return x*p.y-y*p.x;}
};
struct Line{
  Point p1,p2;
  Line(){}
  Line(Point p1, Point p2):p1(p1),p2(p2){}
};
int ccw(Point a,Point b,Point c){
  Point t1=b-a,t2=c-a;
  if(t1.det(t2)> eps) return 1;//counter clockwise
  if(t1.det(t2)< -eps) return -1;//clockwise
  if(t1.dot(t2)< -eps) return 2;//c-a-b online
  if(t1.norm()<t2.norm()) return -2;//a-b-c online
  return 0;//a-c-b online
}
bool intersectSS(Point a,Point b,Point c,Point d){
  return (ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0);
}
bool intersectSS(Line l1,Line l2){
  return intersectSS(l1.p1,l1.p2,l2.p1,l2.p2);
}
bool isOrthogonal(Point a,Point b){
  return fabs(a.dot(b))<eps;
}
bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}
bool isParallel(Point a,Point b){
  return fabs(a.det(b))<eps;
}
bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}
Point CrossPoint(Line l1,Line l2){
    double a=(l1.p2-l1.p1).det(l2.p2-l2.p1);
    double b=(l1.p2-l1.p1).det(l1.p2-l2.p1);
    if(fabs(a)<eps&&fabs(b)<eps) return l2.p1;
    return l2.p1+(l2.p2-l2.p1)*(b/a);
}
Point project(Line l,Point p){
  Point base=l.p2-l.p1;
  double r=(p-l.p1).dot(base)/base.norm();
  return l.p1+base*r;
}
Point reflect(Line l,Point p){
  return p+(project(l,p)-p)*2.0;
}
double distance(Line l,Point p){
    Point r=project(l,p);
    if(abs(ccw(l.p1,l.p2,r))==0) return (p-r).abs();
    else return min((p-l.p1).abs(),(p-l.p2).abs());
}
int main(){
    int q;
    double xp0,yp0,xp1,yp1,xp2,yp2,xp3,yp3;
    cin>>q;
    while(q--){
        cout<<fixed<<setprecision(10);
        cin>>xp0>>yp0>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3;
        Point p0(xp0,yp0),p1(xp1,yp1),p2(xp2,yp2),p3(xp3,yp3);
        if(intersectSS(p0,p1,p2,p3)) cout<<0.0<<endl;
        else cout<<min(min(distance(Line(p0,p1),p2),distance(Line(p0,p1),p3)),
        min(distance(Line(p2,p3),p0),distance(Line(p2,p3),p1)))<<endl;
    }
    return 0;
}