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 <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

const double eps = 1e-10;

class Vector
{
public:
  double x;
  double y;

  Vector(){}
  Vector( double x, double y ) : x(x), y(y) {}

  Vector operator + ( const Vector v ) { return Vector( x + v.x, y + v.y ); }
  Vector operator - ( const Vector v ) { return Vector( x - v.x, y - v.y ); }
  Vector operator * ( const double k ) { return Vector( x * k, y * k ); }
  Vector operator / ( const double k ) { return Vector( x / k, y / k ); }
  bool operator < ( const Vector &v ) const { return x * x + y * y < v.x * v.x + v.y * v.y; }

  double abs() { return sqrt( norm() ); }
  double norm() { return x * x + y * y; }

  static double dot( Vector v1, Vector v2 ) { return v1.x * v2.x + v1.y * v2.y; }
  static double cross( Vector v1, Vector v2 ) { return v1.x * v2.y - v1.y * v2.x; }
};

class Distance
{
public:
  Vector p0, p1, p2, p3;
  Distance(){}
  Distance( Vector p0, Vector p1, Vector p2, Vector p3 ) : p0(p0), p1(p1), p2(p2), p3(p3) {}
  int solve();
  double dist( Vector a, Vector b );
  bool intersect();
};

bool Distance::intersect()
{
  Vector p10 = p1 - p0;
  Vector p21 = p2 - p1;
  Vector p31 = p3 - p1;

  Vector p32 = p3 - p2;
  Vector p03 = p0 - p3;
  Vector p13 = p1 - p3;

  return ( Vector::cross( p10, p21 ) * Vector::cross( p10, p31 ) < 0 &&
           Vector::cross( p32, p03 ) * Vector::cross( p32, p13 ) < 0 );
}

double Distance::dist( Vector a, Vector b )
{
  double ret;
  double dt = Vector::dot( a, b );

  if ( dt < 0 )
    ret = b.abs();
  else if ( dt < a.norm() )
    ret = fabs( Vector::cross( a, b ) ) / a.abs();
  else
    {
      Vector ba = b - a;
      ret = ba.abs();
    }
      
  return ret;
}

int Distance::solve()
{

  double ret;

  if ( intersect() )
    ret = 0;
  else
    ret = min( min( dist( p1 - p0, p2 - p0 ), dist( p1 - p0, p3 - p0 ) ),
               min( dist( p3 - p2, p0 - p2 ), dist( p3 - p2, p1 - p2 ) ) );
  
  cout << fixed << setprecision(10) << ret << endl;
  
  return 0;
}

int main()
{
  int q;
  cin >> q;

  for ( auto i = 0; i < q; ++i )
    {
      double x0, y0, x1, y1, x2, y2, x3, y3;
      cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
      
      Distance d( Vector(x0, y0), Vector(x1, y1), Vector(x2, y2), Vector(x3, y3));

      d.solve();
    }      

  return 0;
}