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;
typedef long long ll;
const int inf = 1e9 + 7;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define eb emplace_back
#define EQ(a, b) abs(a - (b)) < 1e-10
const double eps = 1e-10;
using P = complex<double>;
double dot(P a, P b) {return real(conj(a) * b);}
double cross(P a, P b) {return imag(conj(a) * b);}
struct L : vector<P> {L(const P &a = P(), const P &b = P()) {push_back(a); push_back(b);}};
double distLP(L l, P p) {return abs(cross(l[0] - l[1], p - l[0])) / abs(l[1] - l[0]);
    /*return abs(p - projection(l, p));*/}
double distSP(L l, P p) {
    if (dot(l[1] - l[0], p - l[0]) < eps) return abs(l[0] - p);
    if (dot(l[0] - l[1], p - l[1]) < eps) return abs(l[1] - p);
    return distLP(l, p);
}
double norm(P a) {return a.real() * a.real() + a.imag() * a.imag();}
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
int ccw(P p0, P p1, P p2) {
    P a = p1 - p0;
    P b = p2 - p0;
    if (cross(a, b) > eps) return COUNTER_CLOCKWISE;
    if (cross(a, b) < -eps) return CLOCKWISE;
    if (dot(a, b) < -eps) return ONLINE_BACK;
    if (norm(a) < norm(b)) return ONLINE_FRONT;
    return ON_SEGMENT;
}
bool isec(P p1, P p2, P p3, P p4) {
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
            ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);}
bool isec(L s1, L s2) {return isec(s1[0], s1[1], s2[0], s2[1]);}
double distSS(L a, L b) {
    if (isec(a, b)) return 0.0;
    return min({distSP(a, b[0]), distSP(a, b[1]), distSP(b, a[0]), distSP(b, a[1]), distSP(b, a[0])});
}
int main() {
    int q; cin >> q;
    while (q--) {
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        P p0(x0, y0), p1(x1, y1), p2(x2, y2), p3(x3, y3);
        L s0(p0, p1), s1(p2, p3);
        cout << fixed << setprecision(10) << distSS(s0, s1) << endl;
    }
}