#include<bits/stdc++.h>
#define ll                  long long
#define endl                '\n'
#define MOD                 1000000007
#define sz                  200005
using namespace std;

typedef long double T;
const double eps = 1e-9;
const double PI = acos((double) - 1.0);
int sign(double x) { return (x > eps) - (x < -eps); }

struct PT {
    double x, y;
    PT() { x = 0, y = 0; }
    PT(double x, double y) : x(x), y(y) {}
    PT(const PT &p) : x(p.x), y(p.y)    {}
    PT operator + (const PT &a) const { return PT(x + a.x, y + a.y); }
    PT operator - (const PT &a) const { return PT(x - a.x, y - a.y); }
    PT operator * (const double a) const { return PT(x * a, y * a); }
    friend PT operator * (const double &a, const PT &b) { return PT(a * b.x, a * b.y); }
    PT operator / (const double a) const { return PT(x / a, y / a); }
    bool operator == (PT a) const { return sign(a.x - x) == 0 && sign(a.y - y) == 0; }
    bool operator != (PT a) const { return !(*this == a); }
    bool operator < (PT a) const { return sign(a.x - x) == 0 ? y < a.y : x < a.x; }
    bool operator > (PT a) const { return sign(a.x - x) == 0 ? y > a.y : x > a.x; }
    double norm() { return sqrt(x * x + y * y); }
    double norm2() { return x * x + y * y; }
    PT perp() { return PT(-y, x); }
    double arg() { return atan2(y, x); }
    PT truncate(double r) { // returns a vector with norm r and having same direction
        double k = norm();
        if (!sign(k)) return *this;
        r /= k;
        return PT(x * r, y * r);
    }
};
template <typename T> int sgn(T x) {
    return (T(0) < x) - (x < T(0));
}

istream &operator >> (istream &in, PT &p) { return in >> p.x >> p.y; }
ostream &operator << (ostream &out, PT &p) { return out << "(" << p.x << "," << p.y << ")"; }
inline double dot(PT a, PT b) { return a.x * b.x + a.y * b.y; }
inline double dist2(PT a, PT b) { return dot(a - b, a - b); }
inline double dist(PT a, PT b) { return sqrt(dot(a - b, a - b)); }
inline double cross(PT a, PT b) { return a.x * b.y - a.y * b.x; }
inline double cross2(PT a, PT b, PT c) { return cross(b - a, c - a); }

// find a point from a through b with distance d
PT point_along_line(PT a, PT b, double d) {
    assert(a != b);
    return a + (((b - a) / (b - a).norm()) * d);
}

// minimum distance from point c to line through a and b
double dist_from_point_to_line(PT a, PT b, PT c) {
    return fabs(cross(b - a, c - a) / (b - a).norm());
}


void Solve()
{
    T x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    PT TS(x1, y1);
    PT TG(x2, y2);
    cin >> x1 >> y1 >> x2 >> y2;
    PT AS(x1, y1);
    PT AG(x2, y2);

    T lo = 0.0, hi = max(dist(TS, TG), dist(AS, AG)), mid1, mid2, res = 1e9;
    while (hi - lo > 0.0000001)
    {
        mid1 = lo + (hi - lo) / 3.0;
        mid2 = hi - (hi - lo) / 3.0;
        PT x = point_along_line(TS, TG, mid1);
        PT y = point_along_line(AS, AG, mid1);
        if (mid1 > dist(TS, TG))
            x = TG;
        if (mid1 > dist(AS, AG))
            y = AG;
        T c1 = dist(x, y);
        x = point_along_line(TS, TG, mid2);
        y = point_along_line(AS, AG, mid2);
        if (mid2 > dist(TS, TG))
            x = TG;
        if (mid2 > dist(AS, AG))
            y = AG;
        T c2 = dist(x, y);

        if (c1 < c2 + eps)
        {
            res = c1;
            hi = mid2;
        }
        else {
            res = c2;
            lo = mid1;
        }
    }
    cout << fixed << setprecision(6) << res << endl;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t, T = 1;
    cin >> T;
    for (t = 1; t <= T; t++)
        Solve();
    return 0;
}
