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:
// CGL_2_D.cpp
//
#include <bits/stdc++.h>
using namespace std;

const double EPS = 1e-10;
bool EQ(double a, double b){return fabs(a-b) < EPS;}
typedef complex<double> Point;
#define X real()
#define Y imag()

struct Segment {
  Point p1, p2;
  Segment(){};
  Segment(Point p1, Point p2) : p1(p1), p2(p2) {};
};
typedef Segment Line;
double dot(Point a, Point b){return real(conj(a) * b);}
double cross(Point a, Point b){return imag(conj(a) * b);}

Point project(Segment s, Point p) {
  double r = dot(p - s.p1, s.p2 - s.p1) / norm(s.p2 - s.p1);
  return s.p1 + (s.p2 - s.p1) * r;
}

bool isParallel(Line l1, Line l2) {
  return EQ(cross(l1.p1 - l1.p2, l2.p1 - l2.p2), 0.0);
}

const int COUNTER_CLOCKWISE = +1;
const int CLOCKWISE = -1;
const int ONLINE_BACK = +2;
const int ONLINE_FRONT = -2;
const int ON_SEGMENT = 0;
int ccw(Point a, Point b, Point c) {
  Point x = b - a;
  Point y = c - a;
  if(cross(x, y) > EPS) return COUNTER_CLOCKWISE;
  if(cross(x, y) < -EPS) return CLOCKWISE;
  if(dot(x, y) < -EPS) return ONLINE_BACK;
  if(norm(x) < norm(y)) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersectSS(Segment s1, Segment s2) {
  return ccw(s1.p1, s1.p2, s2.p1) * ccw(s1.p1, s1.p2, s2.p2) <= 0 &&
    ccw(s2.p1, s2.p2, s1.p1) * ccw(s2.p1, s2.p2, s1.p2) <= 0;
}

double distancePP(Point a, Point b) {
  return abs(a - b);
}

double distanceLP(Line l, Point p) {
  return distancePP(p, project(l, p));
}

double distanceSP(Segment s, Point p) {
  if(dot(s.p2 - s.p1, p - s.p1) < -EPS) return distancePP(p, s.p1);
  if(dot(s.p1 - s.p2, p - s.p2) < -EPS) return distancePP(p, s.p2);
  return distanceLP(s, p);
}

double distanceSS(Segment s1, Segment s2) {
  if(intersectSS(s1, s2)) return 0.0;
  return min(min(distanceSP(s1, s2.p1), distanceSP(s1, s2.p2)),
             min(distanceSP(s2, s1.p1), distanceSP(s2, s1.p2)));
}

int main() {
  int q;
  cin>>q;
  int a,b,c,d,e,f,g,h;
  for(int i=0;i<q;++i){
    cin>>a>>b>>c>>d>>e>>f>>g>>h;
    Line s1(Point(a,b), Point(c,d));
    Line s2(Point(e,f), Point(g,h));
    printf("%.10f\n", distanceSS(s1,s2));
  }

  return 0;
}