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 <cstdio>
#include <cmath>
#include <iostream>
 
using namespace std;
const double EPS = 1e-10;
int q;
int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
 
struct Point {
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) { }
    Point operator+(Point p) {
        return Point(x + p.x, y + p.y);
   }
    Point operator-(Point p) {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(double k) {
        return Point(x * k, y * k);
    }
    Point operator/(double k) {
        return Point(x / k, y / k);
    }
    bool operator==(Point p) {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};
typedef Point Vector;
int dcmp(double x) {
    if (fabs(x) < EPS) return 0;
    return x < 0 ? -1 : 1;
}
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;
}
double Length(Vector a) {
    return sqrt(Dot(a, a));
}
double DistancePS(Point p, Point a, Point b) {
    if (a == b) return Length(p - a);
    Vector v1 = b - a, v2 = p - a, v3 = p - b;
    if (Dot(v1, v2) < 0) return Length(v2);
    if (Dot(v1, v3) > 0) return Length(v3);
    return fabs(Cross(v1, v2)) / Length(v1);
}
bool IntersectSS(Point a1, Point a2, Point b1, Point b2) {
    double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1);
    double c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
    return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
 double DistanceSS(Point a1, Point a2, Point b1, Point b2) {
    if (IntersectSS(a1, a2, b1, b2)) return 0.0;
    return min(min(DistancePS(a1, b1, b2), DistancePS(a2, b1, b2)),
               min(DistancePS(b1, a1, a2), DistancePS(b2, a1, a2)));
}
 
int main() {
    cin >> q;
    while (q--) {
        cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;
        Point a1(xp0, yp0);
        Point a2(xp1, yp1);
        Point b1(xp2, yp2);
        Point b2(xp3, yp3);
        printf("%.10lf\n", DistanceSS(a1, a2, b1, b2));
    }
    return 0;
}