#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define db double
const db eps = 1e-8;

struct Point{
    db x, y;
    Point(db x=0, db y=0): x(x), y(y) {}    //必须有初始化
    bool operator < (const Point &p){
        return x < p.x || (x == p.x && y < p.y);
    }
};

typedef Point Vector;
Vector operator + (Vector a, Vector b){ return Point(a.x+b.x, a.y+b.y);}
Vector operator - (Point a, Point b){ return Vector(a.x-b.x, a.y-b.y);}
Vector operator * (Vector a, db k){ return Vector(a.x*k, a.y*k);}
Vector operator / (Vector a, db k){ return Vector(a.x/k, a.y/k);}

//inline将函数名为内联函数，不使用栈空间，直接运算，但不能有while,switch等复杂语句
inline db dot(Vector a, Vector b){
    return a.x*b.x + a.y*b.y;
}
inline db cross(Vector a, Vector b){
    return a.x*b.y - b.x*a.y;
}
db length(Vector a){
    return sqrt(dot(a, a));
}
db angle(Vector a, Vector b){
    return acos(dot(a, b) / length(a) / length(b));
}

int dcmp(db x){ //三态函数，eps间返回0，否则>eps返回1，反之-1
    if(fabs(x) < eps) return 0;
    return x < 0? -1: 1;
}
bool operator == (Point a, Point b){
    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}

struct Segment{
    Point p1, p2;
    Segment(Point p1=Point(0, 0), Point p2 = Point(0, 0)): p1(p1), p2(p2) {};
};
typedef Segment Line;
typedef vector<Point> Polygon;
Point project(Line l, Point p){
    Vector a = l.p2 - l.p1, b = p - l.p1;
    db len_a = dot(a, a);   //这里不加sqrt，是因为下面算投影长度时，要除以两次len_a
    Vector tmp = a * (dot(a, b) / len_a);
    return Point(tmp.x+l.p1.x, tmp.y+l.p1.y);
}
Point reflect(Line l, Point p){
    Point tmp = project(l, p);
    return p + (tmp - p)*2;
}

void line_relation(Point p1, Point p2, Point p3, Point p4){
    Vector a = p2 - p1, b = p4 - p3;
    if(cross(a, b) == 0)
        puts("parallel");
    else if(dot(a, b) == 0)
        puts("orthogonal");
    else
        puts("others");
}
int com_segment_relation(Point p0, Point p1, Point p2){
    Vector a = p1-p0, b = p2-p0;
    db flag = cross(p1-p0, p2-p0);
    if(flag < 0)  return 2;
    else if(flag > 0)  return 1;
    else{       //重合
        if(a.x*b.x < 0 || a.y*b.y < 0) return 3;
        else if(length(a) < length(b)) return 4;
        else return 5;
    }
}

int segment_intersection(Point p1, Point p2, Point p3, Point p4){
    Point node1[2] = {p1, p2}, node2[2] = {p3, p4};
    sort(node1, node1+2), sort(node2, node2+2);
    if(node2[1] < node1[0] || node1[1] < node2[0])
        return 0;       //同一直线上，最大最小排除
    else if(cross(p2-p1, p3-p1)*cross(p2-p1, p4-p1) > 0 || cross(p4-p3, p1-p3)*cross(p4-p3, p2-p3) > 0)
        return 0;
    else
        return 1;
}

Point segment_cross_point(Point p1, Point p2, Point p3, Point p4){
    if(!segment_intersection(p1, p2, p3, p4))
        exit(0);
    Vector a = p2-p1, b1 = p3-p1, b2 = p4-p1;
    db len = length(a);
    db h1 = fabs(cross(a, b1) / len);   //可以省去除len,求t时会消掉
    db h2 = fabs(cross(a, b2) / len);
    db t = h1 / (h1+h2);
    return p3+(p4-p3)*t;
}

Point line_cross_point(Point P, Vector v, Point Q, Vector w){
    if(cross(v, w) == 0)
        exit(0);
    Vector u = P - Q;
    double t = cross(w, u) / cross(v, w);
    return P+v*t;
}

inline db norm(db x){
    return x*x;
}
inline db dist_PtoP(Point p1, Point p2){
    return length(p2-p1);   //转换为向量模
}
db dist_PtoS(Segment s, Point p){
    Point pro = project(s, p);
    if(s.p2 < s.p1) swap(s.p1, s.p2);   //线段两端点必须有序
    if(pro < s.p1 || s.p2 < pro)    //投影点不在线段上
        return min(dist_PtoP(p, s.p1), dist_PtoP(p, s.p2));
    else
        return dist_PtoP(p, pro);
}
inline db dist_PtoL(Line l, Point p){
    db tmp = cross(l.p2-l.p1, p-l.p1) / length(l.p2-l.p1);
    return fabs(tmp);
}
db dist_StoS(Segment s1, Segment s2){
    if(segment_intersection(s1.p1, s1.p2, s2.p1, s2.p2))
        return 0;
    db d1 = dist_PtoS(s2, s1.p1), d2 = dist_PtoS(s2, s1.p2), d3 = dist_PtoS(s1, s2.p1), d4 = dist_PtoS(s1, s2.p2);
    return min(min(d1, d2), min(d3, d4));
}
int main()
{
    Point p1, p2, p3, p4;
    int n;
    cin >>n;
    while(n --){
        cin >>p1.x >>p1.y >>p2.x >>p2.y >>p3.x>>p3.y>>p4.x>>p4.y;
        db ans = dist_StoS(Segment(p1, p2), Segment(p3, p4) );
        printf("%.10f\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3300