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<cmath>
#include<vector>

using namespace std;

static const long double EPS = 1e-10;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2; // p2→p0→p1
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point{
    public: 
    long double x,y;
    Point(long double x = 0.0, long double y = 0.0): x(x), y(y) {}
    Point operator + (Point p) const { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) const { return Point(x-p.x, y-p.y); }
    Point operator * (long double a) const { return Point(x*a, y*a); }
    Point operator / (long double a) const { return Point(x/a, y/a); }
    bool operator < (const Point &p) const { return (x != p.x ? x < p.x : y < p.y); }
    bool operator == (const Point &p) const { return fabsl(x - p.x) < EPS && fabsl(y - p.y) < EPS; }
    long double abs() const { return sqrt(norm()); }
    long double norm() const { return x*x + y*y; }
    long double dot(Point p) const { return x*p.x + y*p.y; }
    long double cross(Point p) const { return x*p.y - y*p.x; }   
};

class Segment{
    public: 
    Point p,q;
    Segment(Point p, Point q): p(p), q(q) {}
};

typedef Point Vector;
typedef Segment Line;

int ccw(Point p0, Point p1, Point p2){
    Point a = p1 - p0;
    Point b = p2 - p0;
    if(a.cross(b) > EPS) return COUNTER_CLOCKWISE;
    if(a.cross(b) < -EPS) return CLOCKWISE;
    if(a.dot(b) < -EPS) return ONLINE_BACK;
    if(a.norm() < b.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

// 線分交差判定
bool intersect(Point p0, Point p1, Point p2, Point p3){
    return ccw(p0, p1, p2) * ccw(p0, p1, p3) <= 0 && ccw(p2, p3, p0) * ccw(p2, p3, p1) <= 0;
}

bool intersect(Segment s1, Segment s2){
    return intersect(s1.p, s1.q, s2.p, s2.q);
}

long double getDistanceLP(Line l, Point p){
    return abs((l.q-l.p).cross(p-l.p)) / (l.q-l.p).abs();
}

long double getDistanceSP(Segment s, Point p){
    if((s.q - s.p).dot(p - s.p) < -EPS) return (p-s.p).abs();
    if((s.p - s.q).dot(p - s.q) < -EPS) return (p-s.q).abs();
    return getDistanceLP(s, p);
}

long double getDistance(Segment s1, Segment s2){
    if(intersect(s1, s2)) return 0.0;
    return min(min(getDistanceSP(s1, s2.p), getDistanceSP(s1, s2.q)), min(getDistanceSP(s2, s1.p), getDistanceSP(s2, s1.q)));
}

int main(){
    int n;
    cin >> n;
    vector<Point> ps(4, Point());
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            cin >> ps[j].x >> ps[j].y;
        }
        Segment s1 = Segment(ps[0], ps[1]);
        Segment s2 = Segment(ps[2], ps[3]);
        printf("%.10Lf\n", getDistance(s1, s2));
    }
}