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-9;

bool same(double a, double b) { return a == b; }

struct P {
    double x, y;
    P() : x(0), y(0) {}
    P(double x, double y) : x(x), y(y) {}
    P operator + (P b) { return P(x + b.x, y + b.y); }
    P operator - (P b) { return P(x - b.x, y - b.y); }
    P operator * (double b) { return P(x * b, y * b); }
    P operator / (double b) { return P(x / b, y / b); }
    double operator * (P b) { return x * b.x + y * b.y; }
    double operator ^ (P b) { return x * b.y - y * b.x; }
    double abs() { return hypot(x, y); }
    P unit() { return *this / abs(); }
};

struct L{
    // ax + by + c = 0
    double a, b ,c, o;
    P pa, pb;
    L() : a(0), b(0), c(0), o(0), pa(), pb() {}
    L(P pa, P pb) : a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), o(atan2(-a, b)), pa(pa), pb(pb) {}
    P project(P p) { return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs()); }
    P reflect(P p) { return p + (project(p) - p) * 2; }
    double get_ratio(P p) { return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs()); }
    bool inside(P p) {
        double z = get_ratio(p);
        return z >= 0 && z <= 1;
    }
};

bool parallel(L x, L y) { return same(x.a * y.b, x.b * y.a); }

P intersect(L x, L y) { return P(-x.b * y.c + x.c * y.b, x.a * y.c - x.c * y.a) / (-x.a * y.b + x.b * y.a); }

int main() {
    int q; cin >> q; while (q--) {
        P p[4]; 
        for (int i = 0; i < 4; ++i) cin >> p[i].x >> p[i].y;
        L l1(p[0], p[1]), l2(p[2], p[3]);
        double ans = 1e12;
        auto update = [&] (P &p, L &l) {
            P z = l.project(p);
            if (l.inside(z)) ans = min(ans, (p - z).abs());
            ans = min({ans, (p - l.pa).abs(), (p - l.pb).abs()});
        };
        if (parallel(l1, l2)) {
            if ((p[2] - l1.project(p[2])).abs() < eps) {
                if (l1.inside(p[2]) || l1.inside(p[3]) || l2.inside(p[0]) || l2.inside(p[1])) ans = 0;
                else ans = min({ans, (p[0] - p[2]).abs(), (p[0] - p[3]).abs(), (p[1] - p[2]).abs(), (p[1] - p[3]).abs()});
            } else {
                update(p[2], l1);
                update(p[3], l1);
                update(p[0], l2);
                update(p[1], l2);
            }
        } else {
            P z = intersect(l1, l2);
            if (l1.inside(z) && l2.inside(z)) ans = 0;
            else {
                update(p[2], l1);
                update(p[3], l1);
                update(p[0], l2);
                update(p[1], l2);
            }
        }
        cout << fixed << setprecision(12) << ans << endl;
    }
}