#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;
}