class Point:

    def __init__(self, x , y):

        self.x = x

        self.y = y

    def __sub__(self, p):

        x_sub = self.x - p.x

        y_sub = self.y - p.y

        return Point(x_sub, y_sub)



class Vector:

    def __init__(self, p):

        self.x = p.x

        self.y = p.y

        self.norm = (p.x ** 2 + p.y ** 2) ** 0.5



def cross(v1, v2):

    return v1.x * v2.y - v1.y * v2.x



def dot(v1, v2):

    return v1.x * v2.x + v1.y * v2.y



def ccw(p0, p1, p2):

    a = Vector(p1 - p0)

    b = Vector(p2 - p0)

    cross_ab = cross(a, b)

    if cross_ab > 0:

        return 1

    elif cross_ab < 0:

        return -1

    elif dot(a, b) < 0:

        return 1

    elif a.norm < b.norm:

        return -1

    else:

        return 0



def intersect(p1, p2, p3, p4):

    if (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0) and \

       (ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0):

        return True

    else:

        return False



def getDistanceSP(sp1, sp2, p):

    a = Vector(sp2 - sp1)

    b = Vector(p - sp1)

    if dot(a, b) < 0:

        return b.norm

    c = Vector(sp1 - sp2)

    d = Vector(p - sp2)

    if dot(c, d) < 0:

        return d.norm

    return abs(cross(a, b) / a.norm)



def getDistance(p1, p2, p3, p4):

    if intersect(p1, p2, p3, p4):

        print("0.00000000")

    else:

        d = min(getDistanceSP(p1, p2, p3), getDistanceSP(p1, p2, p4),

                getDistanceSP(p3, p4, p1), getDistanceSP(p3, p4, p2))

        print("{0:.10f}".format(d))





import sys



file_input = sys.stdin



sq = file_input.readline()



for line in file_input:

    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())

    p0 = Point(x_p0, y_p0)

    p1 = Point(x_p1, y_p1)

    p2 = Point(x_p2, y_p2)

    p3 = Point(x_p3, y_p3)

    getDistance(p0, p1, p2, p3)

def cross(c1, c2):

    return c1.real * c2.imag - c1.imag * c2.real



def dot(c1, c2):

    return c1.real * c2.real + c1.imag * c2.imag



def ccw(p0, p1, p2):

    a = p1 - p0

    b = p2 - p0

    cross_ab = cross(a, b)

    if cross_ab > 0:

        return 1

    elif cross_ab < 0:

        return -1

    elif dot(a, b) < 0:

        return 1

    elif abs(a) < abs(b):

        return -1

    else:

        return 0



def intersect(p1, p2, p3, p4):

    # p1 and p2 are end points of a segment.

    # p3 and p4 are end points of the other segment.

    if (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0) and \

       (ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0):

        return True

    else:

        return False



def get_distance_sp(sp1, sp2, p):

    a = sp2 - sp1

    b = p - sp1

    if dot(a, b) < 0:

        return abs(b)

    c = sp1 - sp2

    d = p - sp2

    if dot(c, d) < 0:

        return abs(d)

    return abs(cross(a, b)) / abs(a)



def print_distance(p1, p2, p3, p4):

    # parameters are the same as intersect.

    if intersect(p1, p2, p3, p4):

        print("0.0000000000")

    else:

        d = min(get_distance_sp(p1, p2, p3), get_distance_sp(p1, p2, p4),

                get_distance_sp(p3, p4, p1), get_distance_sp(p3, p4, p2))

        print("{0:.10f}".format(d))





import sys



file_input = sys.stdin



sq = file_input.readline()



for line in file_input:

    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())

    p0 = x_p0 + y_p0 * 1j

    p1 = x_p1 + y_p1 * 1j

    p2 = x_p2 + y_p2 * 1j

    p3 = x_p3 + y_p3 * 1j

    print_distance(p0, p1, p2, p3)

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __sub__(self, p):
        x_sub = self.x - p.x
        y_sub = self.y - p.y
        return Point(x_sub, y_sub)


class Vector:
    def __init__(self, p):
        self.x = p.x
        self.y = p.y
        self.norm = (p.x**2 + p.y**2) ** 0.5


def cross(v1, v2):
    return v1.x * v2.y - v1.y * v2.x


def dot(v1, v2):
    return v1.x * v2.x + v1.y * v2.y


def ccw(p0, p1, p2):
    a = Vector(p1 - p0)
    b = Vector(p2 - p0)
    cross_ab = cross(a, b)
    if cross_ab > 0:
        return 1
    elif cross_ab < 0:
        return -1
    elif dot(a, b) < 0:
        return 1
    elif a.norm < b.norm:
        return -1
    else:
        return 0


def intersect(p1, p2, p3, p4):
    if (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0) and (
        ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0
    ):
        return True
    else:
        return False


def getDistanceSP(sp1, sp2, p):
    a = Vector(sp2 - sp1)
    b = Vector(p - sp1)
    if dot(a, b) < 0:
        return b.norm
    c = Vector(sp1 - sp2)
    d = Vector(p - sp2)
    if dot(c, d) < 0:
        return d.norm
    return abs(cross(a, b) / a.norm)


def getDistance(p1, p2, p3, p4):
    if intersect(p1, p2, p3, p4):
        print("0.00000000")
    else:
        d = min(
            getDistanceSP(p1, p2, p3),
            getDistanceSP(p1, p2, p4),
            getDistanceSP(p3, p4, p1),
            getDistanceSP(p3, p4, p2),
        )
        print("{0:.10f}".format(d))


import sys

file_input = sys.stdin
sq = file_input.readline()
for line in file_input:
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())
    p0 = Point(x_p0, y_p0)
    p1 = Point(x_p1, y_p1)
    p2 = Point(x_p2, y_p2)
    p3 = Point(x_p3, y_p3)
    getDistance(p0, p1, p2, p3)

def cross(c1, c2):
    return c1.real * c2.imag - c1.imag * c2.real


def dot(c1, c2):
    return c1.real * c2.real + c1.imag * c2.imag


def ccw(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    cross_ab = cross(a, b)
    if cross_ab > 0:
        return 1
    elif cross_ab < 0:
        return -1
    elif dot(a, b) < 0:
        return 1
    elif abs(a) < abs(b):
        return -1
    else:
        return 0


def intersect(p1, p2, p3, p4):
    # p1 and p2 are end points of a segment.
    # p3 and p4 are end points of the other segment.
    if (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0) and (
        ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0
    ):
        return True
    else:
        return False


def get_distance_sp(sp1, sp2, p):
    a = sp2 - sp1
    b = p - sp1
    if dot(a, b) < 0:
        return abs(b)
    c = sp1 - sp2
    d = p - sp2
    if dot(c, d) < 0:
        return abs(d)
    return abs(cross(a, b)) / abs(a)


def print_distance(p1, p2, p3, p4):
    # parameters are the same as intersect.
    if intersect(p1, p2, p3, p4):
        print("0.0000000000")
    else:
        d = min(
            get_distance_sp(p1, p2, p3),
            get_distance_sp(p1, p2, p4),
            get_distance_sp(p3, p4, p1),
            get_distance_sp(p3, p4, p2),
        )
        print("{0:.10f}".format(d))


import sys

file_input = sys.stdin
sq = file_input.readline()
for line in file_input:
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())
    p0 = x_p0 + y_p0 * 1j
    p1 = x_p1 + y_p1 * 1j
    p2 = x_p2 + y_p2 * 1j
    p3 = x_p3 + y_p3 * 1j
    print_distance(p0, p1, p2, p3)

-class Point: -    def __init__(self, x, y): -        self.x = x -        self.y = y - -    def __sub__(self, p): -        x_sub = self.x - p.x -        y_sub = self.y - p.y -        return Point(x_sub, y_sub) +def cross(c1, c2): +    return c1.real * c2.imag - c1.imag * c2.real -class Vector: -    def __init__(self, p): -        self.x = p.x -        self.y = p.y -        self.norm = (p.x**2 + p.y**2) ** 0.5 - - -def cross(v1, v2): -    return v1.x * v2.y - v1.y * v2.x - - -def dot(v1, v2): -    return v1.x * v2.x + v1.y * v2.y +def dot(c1, c2): +    return c1.real * c2.real + c1.imag * c2.imag -    a = Vector(p1 - p0) -    b = Vector(p2 - p0) +    a = p1 - p0 +    b = p2 - p0 -    elif a.norm < b.norm: +    elif abs(a) < abs(b): +    # p1 and p2 are end points of a segment. +    # p3 and p4 are end points of the other segment. -def getDistanceSP(sp1, sp2, p): -    a = Vector(sp2 - sp1) -    b = Vector(p - sp1) +def get_distance_sp(sp1, sp2, p): +    a = sp2 - sp1 +    b = p - sp1 -        return b.norm -    c = Vector(sp1 - sp2) -    d = Vector(p - sp2) +        return abs(b) +    c = sp1 - sp2 +    d = p - sp2 -        return d.norm -    return abs(cross(a, b) / a.norm) +        return abs(d) +    return abs(cross(a, b)) / abs(a) -def getDistance(p1, p2, p3, p4): +def print_distance(p1, p2, p3, p4): +    # parameters are the same as intersect. -        print("0.00000000") +        print("0.0000000000") -            getDistanceSP(p1, p2, p3), -            getDistanceSP(p1, p2, p4), -            getDistanceSP(p3, p4, p1), -            getDistanceSP(p3, p4, p2), +            get_distance_sp(p1, p2, p3), +            get_distance_sp(p1, p2, p4), +            get_distance_sp(p3, p4, p1), +            get_distance_sp(p3, p4, p2), -    p0 = Point(x_p0, y_p0) -    p1 = Point(x_p1, y_p1) -    p2 = Point(x_p2, y_p2) -    p3 = Point(x_p3, y_p3) -    getDistance(p0, p1, p2, p3) +    p0 = x_p0 + y_p0 * 1j +    p1 = x_p1 + y_p1 * 1j +    p2 = x_p2 + y_p2 * 1j +    p3 = x_p3 + y_p3 * 1j +    print_distance(p0, p1, p2, p3)