#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;
}