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<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MON 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))


class Vec{
public:
  double x, y;
  Vec(double x = 0, double y = 0):x(x),y(y){}

  void read(){
    cin >> x >> y;
  }

  void print(){
    printf("%.10lf %.10lf\n", x, y);
  }
  
  Vec operator+(const Vec &other)
  {
    Vec result = *this;
    result.x += other.x;
    result.y += other.y;
    return result;
  }

  Vec operator-(const Vec &other)
  {
    Vec result = *this;
    result.x -= other.x;
    result.y -= other.y;
    return result;
  }

  Vec operator*(const double &k)
  {
    Vec result = *this;
    result.x *= k;
    result.y *= k;
    return result;
  }

  Vec operator/(const double &k)
  {
    Vec result = *this;
    result.x /= k;
    result.y /= k;
    return result;
  } 
  
  double cross(const Vec &other)
  {
    return x*other.y - y*other.x;
  }

  double dot(const Vec &other){
    return x*other.x + y*other.y;
  }
  
  bool operator==(const Vec &other) const
  {
    return abs(x - other.x) < EPS && abs(y - other.y) < EPS;
  }

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

  double norm2()
  {
    return x*x+y*y;
  }

  Vec standard(){
    Vec result = *this;
    return result/result.norm();
  }
};

//ccw:1, cw:-1, other:0
Int CCW(Vec a, Vec b, Vec c){
  b = b - a;
  c = c - a;
  if(b.cross(c) > EPS)return -1;
  if(b.cross(c) < -EPS)return 1;
  return 0;
}

double dist(Vec a, Vec b){
  return (a-b).norm();
}
			

class Line{
public:
  Vec a, b;
  Vec vect;
  Line(Vec a = Vec(), Vec b = Vec()):a(a),b(b),vect(b-a){}

  //projection
  Vec proj(Vec p){
    p = p - a;
    return a + vect * vect.dot(p) / vect.norm2();
  }

  //reflection
  Vec reflect(Vec p){
    return proj(p) * 2 - p;
  }

  bool onSegment(Vec p){
    return abs((p-a).cross(b-a)) < EPS && (p-a).dot(p-b) < EPS;
  }

  //other -> LineSegment(not inclusive), this -> Line
  bool _intersect(Line &other){
    return CCW(a, b, other.a) * CCW(a, b, other.b) < 0;
  }

  //other, this: both are LineSegment(inclusive)
  bool intersect(Line &other){
    return onSegment(other.a) || onSegment(other.b) || other.onSegment(a) || other.onSegment(b) || _intersect(other) && other._intersect(*this);
  }

  //low accuracy
  Vec crossPoint(Line &other){
    double ratio = (a - other.a).cross(vect) / other.vect.cross(vect);
    return other.a + other.vect * ratio;
  }

  double dist(Vec p){
    Vec pp = proj(p);
    if(onSegment(pp))return ::dist(p, pp);
    else return min(::dist(p, a), ::dist(p, b));
  }
  
  double dist(Line &other){
    if(intersect(other))return 0;
    return min(min(dist(other.a), dist(other.b)), min(other.dist(a), other.dist(b)));
  }
};


int main(){
  Int q;
  cin >> q;
  while(q--){
    Vec p0, p1, p2, p3;
    p0.read();
    p1.read();
    p2.read();
    p3.read();
    Line l1(p0, p1), l2(p2, p3);
    printf("%.10lf\n", l1.dist(l2));
  }
  return 0;
}