#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1, i##_end_ = (n); i <= i##_end_; ++i)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;


const double eps = 1e-10;
int sgn(double x) {
    if(fabs(x) < eps) return 0;
    return x < 0 ? -1 : 1;
}
struct Point {
    double x, y;
    Point(double xp=0, double yp=0): x(xp), y(yp) { }
    Point operator + (const Point& rhs) const { return Point(x+rhs.x, y+rhs.y); }
    Point operator - (const Point& rhs) const { return Point(x-rhs.x, y-rhs.y); }
    Point operator * (const double& k) const { return Point(x*k, y*k); }
    Point operator / (const double& k) const { return Point(x/k, y/k); }
    bool operator < (const Point& rhs) const { return x < rhs.x || (x==rhs.x && y<rhs.y); }
    bool operator == (const Point& rhs) const {return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0; }
    Point turn(double rad) { return Point(x*cos(rad)-y*sin(rad), x*sin(rad)+y*cos(rad)); }
    void scan() { scanf("%lf%lf", &x, &y); }
};
typedef Point Vector;

double dot(Vector x, Vector y) { return x.x*y.x + x.y*y.y; }
double length(Vector x) { return sqrt(dot(x, x)); }
double cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }

Point LineProjection(Point P, Point A, Point B) {
    Vector v = B - A;
    return A + v * (dot(P-A, v) / dot(v, v));
}
Point LineReflection(Point P, Point A, Point B) {
    Point proj = LineProjection(P, A, B);
    return proj + proj - P;
}

int Clockwise(Point O, Point A, Point B) {
    /* Clockwise: -1
       Counterclockwise: 1
       Otherwise: 0
    */
    return sgn(cross(A - O, B - O));
}

void SegCheck(Point a, Point b, Point p) {
    Vector d = b - a, e = p - a;
    if(sgn(dot(d, e)) == -1) puts("ONLINE_BACK");
    else if(sgn(length(e) - length(d)) == 1) puts("ONLINE_FRONT");
    else puts("ON_SEGMENT");
}

int JudgeLLParOrth(Point a1, Point a2, Point b1, Point b2) {
    /* 2: parallel
       1: orthogonal
       0: otherwise
    */
    Vector v = a2 - a1, w = b2 - b1;
    if(sgn(cross(v, w)) == 0) return 2;
    if(sgn(dot(v, w)) == 0) return 1;
    return 0;
}

bool CheckSSProperIntersection(Point a1, Point a2, Point b1, Point b2) {
    double c1 = cross(a1 - b1, b2 - b1), c2 = cross(a2 - b1, b2 - b1);
    double c3 = cross(b1 - a1, a2 - a1), c4 = cross(b2 - a1, a2 - a1);
    return sgn(c1) * sgn(c2) == -1 && sgn(c3) * sgn(c4) == -1;
}
bool OnSeg(Point P, Point A, Point B) {
    Vector v = B - P, w = A - P;
    if(sgn(cross(v, w)) != 0) return false;
    return sgn(dot(v, w)) == -1;
}

bool CheckSSIntersection(Point a1, Point a2, Point b1, Point b2) {
    if(a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2) return true;
    if(OnSeg(a1, b1, b2) || OnSeg(a2, b1, b2) || OnSeg(b1, a1, a2) || OnSeg(b2, a1, a2))
        return true;
    return CheckSSProperIntersection(a1, a2, b1, b2);
}

// Ensure lines intersect first!!! cross(v, w) != 0
Point LLIntersection(Point a1, Point a2, Point b1, Point b2) {
    Vector v = a2 - a1, w = b2 - b1, u = a1 - b1;
    assert(cross(v, w) != 0);
    double t1 = cross(w, u) / cross(v, w);
    return a1 + v * t1;
} // Line: 2 Points

Point LLIntPV(Point P, Vector v, Point Q, Vector w) {
    Vector u = P - Q;
    assert(cross(v, w) != 0);
    double t = cross(w, u) / cross(v, w);
    return P + v * t;
} // Line: Point + Vector

double PLDist(Point P, Point A, Point B) {
    return fabs(cross(B - P, A - P) / length(A - B));
}

double PSDist(Point P, Point A, Point B) {
    if(A == B) return length(P - A);
    if(sgn(dot(A-P, B-A)) == 1) return length(A - P);
    if(sgn(dot(B-P, B-A)) == -1) return length(B - P);
    return fabs(cross(B-P, A-P) / length(A-B));
}

double SSDist(Point a1, Point a2, Point b1, Point b2) {
    if(CheckSSIntersection(a1, a2, b1, b2)) return 0.0;
    return min(min(PSDist(a1,b1,b2), PSDist(a2,b1,b2)), min(PSDist(b1,a1,a2), PSDist(b2,a1,a2)));
}

int main() {
    Point a1, a2, b1, b2, res;
    int q; scanf("%d", &q);
    while(q--) {
        a1.scan(), a2.scan();
        b1.scan(), b2.scan();
        printf("%.11f\n", SSDist(a1, a2, b1, b2));
    }
    
    return 0;
}


Measured memory_bytes: 3220