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:
// Written By NewbieChd
#include <iostream>
#include <iomanip>
#include <cmath>
// #define double long double
using namespace std;

const int maxN = 100003;
const double eps = 1e-8, inf = 1e18;
inline double absolute(double x) { return x >= 0 ? x : -x; }
inline double square(double x) { return x * x; }

struct Vector {
    double x, y;
    Vector() {}
    Vector(double x, double y) : x(x), y(y) {}
    friend Vector operator+(const Vector& a, const Vector& b) { return Vector(a.x + b.x, a.y + b.y); }
    friend Vector operator-(const Vector& a, const Vector& b) { return Vector(a.x - b.x, a.y - b.y); }
    friend Vector operator*(const Vector& a, const double& b) { return Vector(a.x * b, a.y * b); }
    friend Vector operator/(const Vector& a, const double& b) { return Vector(a.x / b, a.y / b); }
    inline double length() { return sqrt(square(x) + square(y)); }
    inline void read() { cin >> x >> y; }
    inline void write() { cout << fixed << setprecision(10) << x << ' ' << y << '\n'; }
};
inline double distance(Vector a, Vector b) { return sqrt(square(b.x - a.x) + square(b.y - a.y)); }
inline double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
inline double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }

inline Vector project(Vector a, Vector b, Vector c) {
    b = a - b;
    return b * (dot(b, c - a) / (square(b.x) + square(b.y))) + a;
}
inline Vector reflect(Vector a, Vector b, Vector c) {
    a = project(a, b, c);
    return a * 2 - c;
}

inline bool intersect(Vector a, Vector b, Vector c, Vector d) {
    if (max(min(a.x, b.x), min(c.x, d.x)) > min(max(a.x, b.x), max(c.x, d.x)) + eps || 
        max(min(a.y, b.y), min(c.y, d.y)) > min(max(a.y, b.y), max(c.y, d.y)) + eps || 
        cross(a - c, d - c) * cross(d - c, b - c) + eps < 0 || 
        cross(c - a, b - a) * cross(b - a, d - a) + eps < 0)
        return 0;
    return 1;
}

struct Line {
    double A, B, C;
    Line() {}
    Line(double A, double B, double C) : A(A), B(B), C(C) {}
};
inline Line getLine(Vector a, Vector b) { return Line(b.y - a.y, a.x - b.x, a.y * (b.x - a.x) - a.x * (b.y - a.y)); }
inline Vector crossPoint(Line a, Line b) {
    double tmp = a.A * b.B - a.B * b.A;
    return Vector((a.B * b.C - b.B * a.C) / tmp, (b.A * a.C - a.A * b.C) / tmp);
}

inline double PointSegDistance(Vector a, Vector b, Vector c) {
    Vector l = b - a;
    double tmp;
    if ((tmp = dot(c - a, l) / (square(l.x) + square(l.y))) < eps)
        return distance(c, a);
    if (tmp + eps > 1)
        return distance(c, b);
    return distance(c, project(a, b, c));
}
inline double SegSegDistance(Vector a, Vector b, Vector c, Vector d) {
    if (intersect(a, b, c, d))
        return 0;
    return min(min(PointSegDistance(a, b, c), PointSegDistance(a, b, d)),
               min(PointSegDistance(c, d, a), PointSegDistance(c, d, b)));
}

int main() {
    ios::sync_with_stdio(false);
    int Q;
    Vector a, b, c, d;
    for (cin >> Q; Q; --Q)
        a.read(), b.read(), c.read(), d.read(),
        cout << fixed << setprecision(10) << SegSegDistance(a, b, c, d) << '\n';
    return 0;
}