#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

const double EPS = 1e-9;

int sign(double x) {
    if (fabs(x) < EPS) {
        return 0;
    } else if (x > 0) {
        return 1;
    } else {
        return -1;
    }
}

int dcmp(double x, double y) {
    return sign(x - y);
}

typedef long long ll;

struct Vector;
typedef Vector Point;
struct Segment;
struct Line;

struct Vector {
    double x;
    double y;

    explicit Vector(double x = 0, double y = 0);

    Vector operator+(const Vector &rhs) const;
    Vector operator-() const;
    Vector operator-(const Vector &rhs) const;
    Vector operator*(double d) const;
    Vector operator/(double d) const;

    bool operator==(const Vector &rhs) const;
    bool operator!=(const Vector &rhs) const;
    bool operator<(const Vector &rhs) const;
    bool operator>(const Vector &rhs) const;
    bool operator<=(const Vector &rhs) const;
    bool operator>=(const Vector &rhs) const;

    friend std::ostream &operator<<(std::ostream &os, const Vector &vector);

    double dot(const Vector &rhs) const;
    double cross(const Vector &rhs) const;
    double length() const;
    double angle() const;
    double angle(const Vector &rhs) const;
    Vector rotate(double rad) const;
    Vector normal() const;
    double getDistanceTo(const Point &rhs) const;
    double getDistanceTo(const Line &rhs) const;
    double getDistanceTo(const Segment &rhs) const;
};

struct Line {
    Point a;
    Point b;

    explicit Line(double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0);
    explicit Line(const Point &a = Point(), const Point &b = Point());

    double getDistanceTo(const Point &rhs) const;
    Point getIntersection(const Line &rhs) const;
    Point getProjection(const Point &rhs) const;
    Point getReflection(const Point &rhs) const;
    bool contains(const Point &rhs) const;
    bool intersects(const Line &rhs) const;
};

struct Segment {
    Point a;
    Point b;

    explicit Segment(double x1 = 0, double y1 = 0, double x2 = 0, double y2 = 0);
    explicit Segment(const Point &a = Point(), const Point &b = Point());

    double length() const;
    bool contains(const Point &rhs, bool containsEndPoints = true) const;
    bool intersects(const Segment &rhs, bool containsEndPoints = true) const;
    Point getIntersection(const Segment &rhs) const;
    double getDistanceTo(const Point &rhs) const;
    double getDistanceTo(const Segment &rhs) const;
};


Vector::Vector(double x, double y) : x(x), y(y) {}

Vector Vector::operator+(const Vector &rhs) const {
    return Vector(x + rhs.x, y + rhs.y);
}

Vector Vector::operator-() const {
    return Vector(-x, -y);
}

Vector Vector::operator-(const Vector &rhs) const {
    return *this + -rhs;
}

Vector Vector::operator*(double d) const {
    return Vector(x * d, y * d);
}

Vector Vector::operator/(double d) const {
    return Vector(x / d, y / d);
}


bool Vector::operator==(const Vector &rhs) const {
    return dcmp(x, rhs.x) == 0 && dcmp(y, rhs.y) == 0;
}

bool Vector::operator!=(const Vector &rhs) const {
    return !(rhs == *this);
}

bool Vector::operator<(const Vector &rhs) const {
    if (dcmp(x, rhs.x) != 0) {
        return dcmp(x, rhs.x) < 0;
    } else {
        return dcmp(y, rhs.y) < 0;
    }
}

bool Vector::operator>(const Vector &rhs) const {
    return rhs < *this;
}

bool Vector::operator<=(const Vector &rhs) const {
    return !(rhs < *this);
}

bool Vector::operator>=(const Vector &rhs) const {
    return !(*this < rhs);
}

std::ostream &operator<<(std::ostream &os, const Vector &vector) {
    os << "(" << vector.x << ", " << vector.y << ")";
    return os;
}

double Vector::dot(const Vector &rhs) const {
    return x * rhs.x + y * rhs.y;
}

double Vector::cross(const Vector &rhs) const {
    return x * rhs.y - rhs.x * y;
}

double Vector::length() const {
    return sqrt(dot(*this));
}

double Vector::angle() const {
    return atan2(y, x);
}

double Vector::angle(const Vector &rhs) const {
    return acos(dot(rhs) / length() / rhs.length());
}

Vector Vector::rotate(double rad) const {
    return Vector(x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad));
}

Vector Vector::normal() const {
    double l = length();
    return Vector(-y / l, x / l);
}

double Vector::getDistanceTo(const Point &rhs) const {
    return sqrt(pow(x - rhs.x, 2) + pow(y - rhs.y, 2));
}

double Vector::getDistanceTo(const Line &rhs) const {
    return rhs.getDistanceTo(*this);
}

double Vector::getDistanceTo(const Segment &rhs) const {
    return rhs.getDistanceTo(*this);
}

Line::Line(double x1, double y1, double x2, double y2) : a(x1, y1), b(x2, y2) {}

Line::Line(const Point &a, const Point &b) : a(a), b(b) {}

double Line::getDistanceTo(const Point &rhs) const {
    const Vector &v1 = b - a;
    const Vector &v2 = rhs - a;
    return fabs(v1.cross(v2) / v1.length());
}

Point Line::getIntersection(const Line &rhs) const {
    if (!intersects(rhs)) {
        return Point();
    }
    Vector u = a - rhs.a;
    Vector v = b - a;
    Vector w = rhs.b - rhs.a;
    double t = w.cross(u) / v.cross(w);
    return a + v * t;
}

Point Line::getProjection(const Point &rhs) const {
    const Vector &v = b - a;
    return a + v * (v.dot(rhs - a) / v.dot(v));
}

Point Line::getReflection(const Point &rhs) const {
    return getProjection(rhs) * 2 - rhs;
}

bool Line::contains(const Point &rhs) const {
    Point p1 = a;
    Point p2 = b;
    if (p1 == rhs) {
        p1 = p1 + (p2 - p1) * 2;
    } else if (p2 == rhs) {
        p2 = p2 + (p1 - p2) * 2;
    }
    return sign((p2 - rhs).cross(p1 - rhs)) == 0;
}

bool Line::intersects(const Line &rhs) const {
    return dcmp((b - a).angle(), (rhs.b - rhs.a).angle()) != 0;
}

Segment::Segment(double x1, double y1, double x2, double y2) : a(x1, y1), b(x2, y2) {}

Segment::Segment(const Point &a, const Point &b) : a(a), b(b) {}

double Segment::length() const {
    return a.getDistanceTo(b);
}

bool Segment::contains(const Point &rhs, bool containsEndPoints) const {
    const Vector &u = a - rhs;
    const Vector &v = b - rhs;
    return sign(u.cross(v)) == 0 && (containsEndPoints ? sign(u.dot(v)) <= 0 : sign(u.dot(v)) < 0);
}

bool Segment::intersects(const Segment &rhs, bool containsEndPoints) const {
    const Vector &u = b - a;
    const Vector &v = rhs.b - rhs.a;
    double c1 = u.cross(rhs.a - a);
    double c2 = u.cross(rhs.b - a);
    double c3 = v.cross(a - rhs.a);
    double c4 = v.cross(b - rhs.a);
    if (containsEndPoints && (!sign(c1) || !sign(c2) || !sign(c3) || !sign(c4))) {
        return contains(rhs.a) || contains(rhs.b) || rhs.contains(a) || rhs.contains(b);
    }
    return sign(c1) * sign(c2) < 0 && sign(c3) * sign(c4) < 0;
}

Point Segment::getIntersection(const Segment &rhs) const {
    // TODO get intersection with a segment
    return Point();
}

double Segment::getDistanceTo(const Point &rhs) const {
    if (a == b) {
        return a.getDistanceTo(rhs);
    }
    const Vector &v1 = b - a;
    const Vector &v2 = rhs - a;
    const Vector &v3 = rhs - b;
    if (sign(v1.dot(v2)) < 0) {
        return v2.length();
    } else if (sign(v1.dot(v3)) > 0) {
        return v3.length();
    } else {
        return rhs.getDistanceTo(Line(a, b));
    }
}

double Segment::getDistanceTo(const Segment &rhs) const {
    if (intersects(rhs)) {
        return 0;
    } else {
        return std::min(std::min(a.getDistanceTo(rhs), b.getDistanceTo(rhs)), std::min(rhs.a.getDistanceTo(*this), rhs.b.getDistanceTo(*this)));
    }
}


int main() {
//    freopen("data.in", "r", stdin);

    int q;
    scanf("%d", &q);
    while (q--) {
        int x1, y1;
        int x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        Segment segment1(x1, y1, x2, y2);
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        Segment segment2(x1, y1, x2, y2);
        printf("%.10f\n", segment1.getDistanceTo(segment2));
    }
    return 0;
}


Measured memory_bytes: 3212