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:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

const double EPS = 1e-10;
#define equals(a, b) (fabs((a) - (b)) < EPS)

struct Point{
    double x, y;
    Point(){}
    Point(double x0, double y0){
        x = x0; y = y0;
    }

    Point operator +(const Point &p){
        return Point(x + p.x, y + p.y);
    }
    Point operator -(const Point &p){
        return Point(x - p.x, y - p.y);
    }
    Point operator *(const double &a){
        return Point(a * x, a * y);
    }
    Point operator /(const double &a){
        return Point(x / a, y / a);
    }

    bool operator == (const Point &p){
        return equals(x, p.x) && equals(y, p.y);
    }

    bool operator < (const Point &p){
        return x != p.x ? x < p.x : y < p.y ;
    }

};

double norm(Point p){
    return p.x * p.x + p.y * p.y;
}

double v_abs(Point p){
    return sqrt(norm(p));
}

typedef Point Vector;

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}


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

double getDistance(Point p1, Point p2, Point p){
    Vector a = p2 - p1, b = p - p1;
    if(dot(a, b) < -EPS) return v_abs(b);

    a = p1 - p2, b = p - p2;
    if(dot(a, b) < -EPS) return v_abs(b);

    return abs(cross(a, b)) / v_abs(a);
}

int main(){
    int Q;
    cin >> Q;
    rep(i, Q){
        Point p0, p1, p2, p3;
        cin >> p0.x >> p0.y;
        cin >> p1.x >> p1.y;
        cin >> p2.x >> p2.y;
        cin >> p3.x >> p3.y;
        if(ccw(p0, p1, p2) * ccw(p0, p1, p3) <= 0 && ccw(p2, p3, p0) * ccw(p2, p3, p1) <= 0 ){
            printf("%.10lf\n", 0.0);
        } else {
            double ans = min(min(getDistance(p0, p1, p2), getDistance(p0, p1, p3)),
                         min(getDistance(p2, p3, p0), getDistance(p2, p3, p1)));
            printf("%.10lf\n", ans);
        }
    }
}