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:
#define loop(i, s, e) for(ll i = s;i < e;i++)

#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

typedef long long signed ll;

template<typename T>
class Vector2D {
public:
    T x;
    T y;

    Vector2D() {
        x = y = 0;
    }

    Vector2D(T x_, T y_) {
        x = x_;
        y = y_;
    }

    T operator*(const Vector2D<T> *e) {
        return this->x * e->x + this->y * e->y;
    }

    Vector2D<T> operator-(const Vector2D<T> *e) {
        return Vector2D<T>(this->x - e->x, this->y - e->y);
    }

    Vector2D<T> operator+(const Vector2D<T> *e) {
        return Vector2D<T>(this->x + e->x, this->y + e->y);
    }

    T operator*(const Vector2D<T> e) {
        return this->x * e.x + this->y * e.y;
    }

    Vector2D<T> operator-(const Vector2D<T> e) {
        return Vector2D<T>(this->x - e.x, this->y - e.y);
    }

    Vector2D<T> operator+(const Vector2D<T> e) {
        return Vector2D<T>(this->x + e.x, this->y + e.y);
    }

    Vector2D<T> operator*(const T r) {
        return Vector2D<T>(this->x * r, this->y * r);
    }

    Vector2D<T> operator/(const T r) {
        return Vector2D<T>(this->x / r, this->y / r);
    }

    double abs() {
        return sqrt(x * x + y * y);
    }

    T abs2() {
        return x * x + y * y;
    }

    T cross(Vector2D<T> e) {
        if(x * e.y >= y * e.x) return (x * e.y) - (y * e.x);
        else return (y * e.x) - (x * e.y);
    }

    double cos(Vector2D<T> e) {
        return (e * (*this)) / (e.abs() * abs());
    }

    double sin(Vector2D<T> e) {
//        if(e.abs() * this->abs() == 0.0) throw ;
        return ((x * e.y) - (y * e.x)) / (e.abs() * abs());
    }
};

typedef Vector2D<double> vdd;

double dist__(double x0, double y0, double x1, double y1, double xx, double yy) {
    int b = 0;
    vdd p[3] = {vdd(x0, y0), vdd(x1, y1), vdd(xx, yy)};
    if (((p[0] - p[1]) * (p[2] - p[1])) < 0) b = -1;
    if (((p[1] - p[0]) * (p[2] - p[0])) < 0) b = 1;
    if (b == 1) return (p[2] - p[0]).abs();
    if (b == -1) return (p[2] - p[1]).abs();
    return (p[1] - p[0]).cross(p[2] - p[0]) / (p[1] - p[0]).abs();
}

double dist(double x0, double y0, double x1, double y1, double xx, double yy){
    double res = dist__(x0,y0,x1,y1,xx,yy);
//    cout << res << endl;
    return res;
}
int main() {
    int q;
    cin >> q;
    loop(i, 0, q) {
        int x[4], y[4];
        vdd v[4];
        loop(j, 0, 4) {
            cin >> x[j] >> y[j];
            v[j] = vdd(x[j], y[j]);
        }
        if ((v[0] - v[1]).sin(v[2] - v[1]) * (v[0] - v[1]).sin(v[3] - v[1]) < 0 && (v[2] - v[3]).sin(v[0] - v[3]) * (v[2] - v[3]).sin(v[1] - v[3]) < 0) cout << 0 << endl;
        else
            cout << setprecision(16)
                 << min(min(dist(x[0], y[0], x[1], y[1], x[2], y[2]), dist(x[0], y[0], x[1], y[1], x[3], y[3])),
                        min(dist(x[2], y[2], x[3], y[3], x[0], y[0]), dist(x[2], y[2], x[3], y[3], x[1], y[1])))
                 << endl;
    }
}