#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
struct Node
{
    double x, y;
    Node(double xx = 0, double yy = 0){
        x = xx; y = yy;
    }

    Node operator + (Node b){
        return Node(x+b.x, y+b.y);
    }
    Node operator - (Node b){
        return Node(x-b.x, y-b.y);
    }
    Node operator * (double a){
        return Node(a*x, a*y);
    }
    Node operator / (double a){
        return Node(x/a, y/a);
    }

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

    bool operator < (const Node &p) const{
        return x!=p.x ? x<p.x : y<p.y;
    }

    bool operator == (const Node &p) const {
        return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
    }
};

bool equals(double a, double b) {
    return fabs(a)-fabs(b) < eps;
}

typedef Node vtr;

struct line{
    Node a, b;
    line(Node x, Node y){
        a = x, b = y;
    }
};

//向量点积
double dot(vtr a, vtr b){
    return a.x*b.x+a.y*b.y;
}

//向量叉积
double cross(vtr a, vtr b){
    return a.x*b.y-a.y*b.x;
}

//两点之间距离
double getDistance_Node(Node a, Node b){
    return (a-b).len();
}

//直线与点的距离
double getDistance_LP(line l, Node p){
    return abs(cross(l.b-l.a, p-l.a)/(l.b-l.a).len());
}

//线段与点的距离
double getDistance_SP(line s, Node p)
{
    if(dot(s.b-s.a, p-s.a)<0.0) return (p-s.a).len();
    if(dot(s.a-s.b, p-s.b)<0.0) return (p-s.b).len();
    return getDistance_LP(s, p);
}

//判断向量a,b是否正交(垂直)
bool isOrthogonal(vtr a, vtr b){
    return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Node a1, Node a2, Node b1, Node b2){
    return isOrthogonal(a1-a2, b1-b2);
}

bool isOrthogonal(line s1, line s2){
    return equals(dot(s1.b-s1.a, s2.b-s2.a), 0.0);
}

//判断向量a,b是否平行
bool isParallel(vtr a, vtr b){
    return equals(cross(a, b), 0.0);
}

bool isParallel(Node a1, Node a2, Node b1, Node b2){
    return isParallel(a1-a2, b1-b2);
}

bool isParallel(line s1, line s2){
    return equals(cross(s1.b-s1.a, s2.b-s2.a), 0.0);
}

//投影 求垂足坐标
//点p在直线p1p2上的投影
Node project(line s, Node p)
{
    vtr base = s.b-s.a;
    //算出比例
    double r = dot(p-s.a, base)/base.norm();
    return s.a+base*r;
}

//映象 求p以直线s为对称轴的对称点
Node reflect(line s, Node p){
    return p+(project(s, p)-p)*2.0;
}

int ccw(Node p0, Node p1, Node p2)
{
    vtr a = p1-p0, b = p2-p0;
    //b在a的逆时针方向
    if(cross(a, b) > eps) return 1;
    //顺时针方向
    if(cross(a, b) < -eps) return -1;
    //共线但反向
    if(dot(a, b) < -eps) return 2;
    //共线同向
    //b更长一点
    if(a.norm() < b.norm()) return -2;
    //a更长一点
    return 0;
}

//判断两线段是否相交
bool intersect(Node p1, Node p2, Node p3, Node p4){
    bool t1 = ccw(p1, p2, p3)*ccw(p1, p2, p4)<=0;
    bool t2 = ccw(p3, p4, p1)*ccw(p3, p4, p2)<=0;
    return t1&&t2;
}
bool intersect(line s1, line s2){
    return intersect(s1.a, s1.b, s2.a, s2.b);
}

//求线段交点
Node getCrossPoint(line s1, line s2)
{
    vtr base = s2.b-s2.a;
    double d1 = abs(cross(base, s1.a-s2.a));
    double d2 = abs(cross(base, s1.b-s2.a));
    double t = d1/(d1+d2);
    return s1.a+(s1.b-s1.a)*t;
}

//求线段距离
double getDistance_SS(line s1, line s2)
{
    //相交距离为0
    if(intersect(s1, s2)) return 0.0;
    double t1 = getDistance_SP(s1, s2.a);
    double t2 = getDistance_SP(s1, s2.b);
    double t3 = getDistance_SP(s2, s1.a);
    double t4 = getDistance_SP(s2, s1.b);
    return min(min(min(t1, t2), t3), t4);
}


int main()
{
    Node p0, p1, p2, p3;
    int q; cin >> q;
    while(q--)
    {
        cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
        line s1 = line(p0, p1);
        line s2 = line(p2, p3);
        double ans = getDistance_SS(s1, s2);
        printf("%.10f\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3284