#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>

#define dTolerance 1.0e-10
using namespace std;

struct POINT{
    double x;
    double y;
};

int LF_COUNTER_CLOCKWIZE(const POINT &p, const POINT &p0, const POINT &p1){
    if((p1.x - p0.x) * (p.y - p0.y) - (p.x - p0.x) * (p1.y - p0.y) > dTolerance){
        return 1;
    } else if((p1.x - p0.x) * (p.y - p0.y) - (p.x - p0.x) * (p1.y - p0.y) < -dTolerance){
        return -1;
    } else {
        return 0;
    }
}

int LF_INTERSECT(const POINT &p0, const POINT &p1, const POINT &p2, const POINT &p3){
    if(LF_COUNTER_CLOCKWIZE(p0,p2,p3) == 0 && LF_COUNTER_CLOCKWIZE(p1,p2,p3) == 0){
        if(fabs(p0.x - p1.x) < dTolerance){    //y軸平行  y座標比較
            if(max(p0.y, p1.y) + dTolerance < min(p2.y, p3.y) || max(p2.y, p3.y) + dTolerance < min(p0.y, p1.y)){    //交わらない
                    return -1;
                } else {    //交わる
                    return 1;;
                }
        }
        if(max(p0.x, p1.x) + dTolerance < min(p2.x, p3.x) || max(p2.x, p3.x) + dTolerance < min(p0.x, p1.x)){    //交わらない
            return -1;
        } else {    //交わる
            return 1;;
        }
    }
    if(LF_COUNTER_CLOCKWIZE(p0,p2,p3) * LF_COUNTER_CLOCKWIZE(p1,p2,p3) == 1 || LF_COUNTER_CLOCKWIZE(p2,p0,p1) * LF_COUNTER_CLOCKWIZE(p3,p0,p1) == 1){
        return 0;
    }
    return 1;
}

double dDist(const POINT &a, const POINT &b){
    return sqrt((a.x - b.x) * (a.x -b.x) + (a.y - b.y) * (a.y - b.y));
}

bool LF_PROJECTION_ON_SEGMENT(const POINT &p, const POINT &p0, const POINT &p1){
    if( (p.x - p0.x) * (p1.x - p0.x) + (p.y - p0.y) * (p1.y - p0.y) > -dTolerance &&
        (p.x - p1.x) * (p0.x - p1.x) + (p.y - p1.y) * (p0.y - p1.y) > -dTolerance ){
            return true;
    }
    return false;    
}

double LF_DIST_POINT_LINE(const POINT &p, const POINT &p0, const POINT &p1){
    double dTmp = dDist(p, p0) * dDist(p, p0) - ( (p.x - p0.x) * (p1.x - p0.x) + (p.y - p0.y) * (p1.y - p0.y) ) * ( (p.x - p0.x) * (p1.x - p0.x) + (p.y - p0.y) * (p1.y - p0.y) ) 
                                               / (dDist(p0, p1) * dDist(p0, p1));
    return sqrt(dTmp);
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        POINT zp0,zp1,zp2,zp3;
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &zp0.x, &zp0.y, &zp1.x, &zp1.y, &zp2.x, &zp2.y, &zp3.x, &zp3.y);
//        printf("%d   ",LF_INTERSECT(zp0,zp1,zp2,zp3));
        if(LF_INTERSECT(zp0, zp1, zp2, zp3) == 1){
            printf("%.15lf\n", 0.0);
        } else {
            vector<double> vdDistance;
            vdDistance.push_back(dDist(zp0, zp2));
            vdDistance.push_back(dDist(zp1, zp2));
            vdDistance.push_back(dDist(zp0, zp3));
            vdDistance.push_back(dDist(zp1, zp3));
            if(LF_PROJECTION_ON_SEGMENT(zp0, zp2, zp3)){
                vdDistance.push_back(LF_DIST_POINT_LINE(zp0, zp2, zp3));
            }
            if(LF_PROJECTION_ON_SEGMENT(zp1, zp2, zp3)){
                vdDistance.push_back(LF_DIST_POINT_LINE(zp1, zp2, zp3));
            }
            if(LF_PROJECTION_ON_SEGMENT(zp2, zp0, zp1)){
                vdDistance.push_back(LF_DIST_POINT_LINE(zp2, zp0, zp1));
            }
            if(LF_PROJECTION_ON_SEGMENT(zp3, zp0, zp1)){
                vdDistance.push_back(LF_DIST_POINT_LINE(zp3, zp0, zp1));
            }
            sort(vdDistance.begin(), vdDistance.end());
            printf("%.15lf\n", vdDistance[0]);
        }
    }
    return 0;
}


Measured memory_bytes: 2796