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 <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double inf = 1e20;
inline double sqr (double k) {return k * k;}
inline int sgn (double p) {
    if (fabs (p) < eps) return 0;
    if (p < 0) return -1;
    return 1;
}
struct point {
    double x, y;
    point (){}
    point (double _x, double _y) {
        x = _x, y = _y;
    }
    void input () {
        scanf ("%lf %lf", &x, &y);
    }
    bool operator == (point b) const {
        return sgn (x - b.x) == 0 && sgn (y - b.y) == 0;
    }
    point operator - (const point &b) const {
        return point (x - b.x, y - b.y);
    }
    double operator * (const point &b) const {
        return x * b.x + y * b.y;
    }
    double operator ^ (const point &b) const {
        return x * b.y - y * b.x;
    }
    double len () {
        return hypot (x, y);
    }
    double len2 () {
        return x * x + y * y;
    }
    double distance (point p) {
        return hypot (x - p.x, y - p.y);
    }
    point operator + (const point &b) const{
        return point (x + b.x, y + b.y);
    }
    point operator * (const double &b) const {
        return point (x * b, y * b);
    }
    point operator / (const double &b) const {
        return point (x / b, y / b);
    }
    double cross (point a, point b) {
        return (a - *this) ^ (b - *this);
    }
    double dot (point a, point b) {
        return (a - *this) * (b - *this);
    }
    bool on_seg (point a, point b) {
        return sgn (cross (a, b)) == 0 && dot (a, b) <= 0;
    }
};
bool seg (point a, point b, point c, point d) {
    if (a.on_seg (c, d) || b.on_seg (c, d) || c.on_seg (a, b) || d.on_seg (a, b)) return true;
    if (a.cross (b, d) * a.cross (b, c) < 0 && c.cross (d, b) * c.cross (d, a) < 0) return true;
    return false;
}
bool check (point p, point a, point b) {
    point x = b - a;
    double k = x.len ();
    double u = a.dot (p, b) / k;
    x = (x / k) * u;
    x = x + a;
//    cout << x.x << ' ' << x.y << endl;
    if (x.on_seg (a, b)) return true;
    return false;
//        return true;
}
int main () {
//    freopen ("in.txt", "r", stdin);
    int Q;
    cin >> Q;
    while (Q --) {
        double ans = inf, x, y;
        point s1, e1, s2, e2, a, b, c;
        s1.input (), e1.input ();
        s2.input (), e2.input ();
        if (seg (s1, e1, s2, e2)) ans = 0;
        else {
            a = e1 - s1;
            b = e2 - s2;
            x = a.len ();
            y = b.len ();
            ans = min (ans, hypot (s1.x - s2.x, s1.y - s2.y));
            ans = min (ans, hypot (s1.x - e2.x, s1.y - e2.y));
            ans = min (ans, hypot (e1.x - s2.x, e1.y - s2.y));
            ans = min (ans, hypot (e1.x - e2.x, e1.y - e2.y));
            if (check (s1, s2, e2)) ans = min (ans, fabs (s2.cross (e2, s1)) / y);
            if (check (e1, s2, e2)) ans = min (ans, fabs (s2.cross (e2, e1)) / y);
            if (check (s2, s1, e1)) ans = min (ans, fabs (s1.cross (e1, s2)) / x);
            if (check (e2, s1, e1)) ans = min (ans, fabs (s1.cross (e1, e2)) / x);
        }
        printf ("%.10f\n", ans);
    }
    return 0;
}