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<iostream>
#include<complex>
#include<array>
#include<vector>
#include<cstdio>
#include<cassert>
using namespace std;

const double EPS = 1e-10;
template<class T>
bool eq(const T& a, const T& b) {return abs(a - b) < EPS;}

typedef  complex<double> point;

double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
	return real(conj(a)*b);
}
int ccw(point a, point b, point c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;  // counter clockwise
	if (cross(b, c) < 0)   return -1;  // clockwise
	if (dot(b, c) < 0)     return +2;  // c--a--b on line
	if (norm(b) < norm(c)) return -2;  // a--b--c on line
	return 0;  // a--c--b on line or a----bc
}

typedef array<point, 2> line;

point projection(const line& l, const point& p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}

point reflection(const line& l, const point& p) {
return p + 2. * (projection(l, p) - p);
}
 typedef array<point, 2> line;
//using line = array<point, 2>;
/*
 * 平行かどうか
 */
bool is_parallel(const line& s, const line& t) {
	return eq(cross(s[0] - s[1], t[0] - t[1]), 0.0);
}

bool is_orthogonal(const line& s, const line& t) {
	return eq(dot(s[0] - s[1], t[0] - t[1]), 0.0);
}

// 交差
// Lはline（直線)
// Sはsegment(線分)
bool intersectLL(const line& l, const line& m) {
	return !eq(cross(l[1]-l[0], m[1]-m[0]), 0.) || // non-parallel
			eq(cross(l[1]-l[0], m[0]-l[0]), 0.);   // same line
}
bool intersectLS(const line& l, const line& s) {
	return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
	cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const line& l, const point& p) {
	return eq(cross(l[1]-p, l[0]-p), 0.);
}
bool intersectSS(const line &s, const line &t) {
	return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
			ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const line &s, const point &p) {
	return abs(s[0]-p) + abs(s[1]-p) - abs(s[1]-s[0]) < EPS; // triangle inequality
}
point crosspoint(const line& l, const line& m) {
	double A = cross(l[1] - l[0], m[1] - m[0]);
	double B = cross(l[1] - l[0], l[1] - m[0]);
	if (eq(A, 0.) && eq(B, 0.)) return m[0]; // same line
	if (eq(A, 0.)) assert(false); // 交点が無い場合に落ちる 実行前に交差判定
	return m[0] + B / A * (m[1] - m[0]);
}


/* 距離 */
// Lはline（直線)
// Sはsegment(線分)
double distanceLP(const line& l, const point& p) {
  return abs(p - projection(l, p));
}
double distanceLL(const line& l, const line& m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const line& l, const line& s) {
if (intersectLS(l, s)) return 0;
 return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const line& s, const point& p) {
  const point r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const line& s, const line& t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
	     min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

int main()
{
  int q;
  cin>>q;
  for(;q--;)
    {
      line l1,l2;
      double x,y;
      cin>>x>>y;
      l1[0]=point(x,y);
      cin>>x>>y;
      l1[1]=point(x,y);
      cin>>x>>y;
      l2[0]=point(x,y);
      cin>>x>>y;
      l2[1]=point(x,y);
      printf("%.10lf\n",distanceSS(l1,l2));
    }
}