Problem: For given two segments s1 and s2, print the distance between them.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.

Input

The entire input looks like:


q (the number of queries)
1st query
2nd query
...
qth query


Each query consists of integer coordinates of end points of s1 and s2 in the following format:


xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3


Output

For each query, print the distance. The output values should be in a decimal fraction with an error less than 0.00000001.

Example

Input

3
0 0 1 0 0 1 1 1
0 0 1 0 2 1 1 2
-1 0 1 0 0 1 0 -1


Output

1.0000000000
1.4142135624
0.0000000000

Solution (in PYTHON):

Solution:
from math import sqrt
for t in xrange(input()):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, raw_input().split())
    dx0 = x1 - x0
    dy0 = y1 - y0
    dx1 = x3 - x2
    dy1 = y3 - y2

    s = (y0-y2)*dx1 - (x0-x2)*dy1
    sm = dx0*dy1 - dy0*dx1
    if s < 0:
        s = -s
        sm = -sm
    t = (y2-y0)*dx0 - (x2-x0)*dy0
    tm = dx1*dy0 - dy1*dx0
    intersection = 0
    if t < 0:
        t = -t
        tm = -tm
    dis = sqrt(
            min(
                (x2-x0)**2 + (y2-y0)**2,
                (x3-x0)**2 + (y3-y0)**2,
                (x2-x1)**2 + (y2-y1)**2,
                (x3-x1)**2 + (y3-y1)**2
                )
            )
    ov = dx0*dy1 - dy0*dx1
    if 0 <= s <= max(sm, 0) and 0 <= t <= max(tm, 0):
        if ov == 0:
            r0 = dx0**2 + dy0**2
            r1 = (x2-x0)*dx0 + (y2-y0)*dy0
            r2 = (x3-x0)*dx0 + (y3-y0)*dy0
            if r1 > r2: r1, r2 = r2, r1
            if r2 < 0 or r0 < r1:
                intersection = 0
            else:
                intersection = 1
        else:
            intersection = 1
    else:
        if ov == 0:
            r0 = dx0**2 + dy0**2
            r1 = dx0*(x2-x0) + dy0*(y2-y0)
            r2 = dx0*(x3-x0) + dy0*(y3-y0)
            if 0 <= r2 and r1 <= r0:
                dis = min(dis, abs(dx0*(y2-y0) - dy0*(x2-x0)) / sqrt(r0))
        else:
            r0 = dx0**2 + dy0**2
            r1 = dx0*(x2-x0) + dy0*(y2-y0)
            r2 = dx0*(x3-x0) + dy0*(y3-y0)
            if 0 <= r1 <= r0:
                o1 = abs(dx0*(y2-y0) - dy0*(x2-x0))
                dis = min(dis, o1 / sqrt(r0))
            if 0 <= r2 <= r0:
                o2 = abs(dx0*(y3-y0) - dy0*(x3-x0))
                dis = min(dis, o2 / sqrt(r0))
            s0 = dx1**2 + dy1**2
            s1 = dx1*(x0-x2) + dy1*(y0-y2)
            s2 = dx1*(x1-x2) + dy1*(y1-y2)
            if 0 <= s1 <= s0:
                o1 = abs(dx1*(y0-y2) - dy1*(x0-x2))
                dis = min(dis, o1 / sqrt(s0))
            if 0 <= s2 <= s0:
                o2 = abs(dx1*(y1-y2) - dy1*(x1-x2))
                dis = min(dis, o2 / sqrt(s0))

        intersection = 0
    if intersection:
        print "%.09f" % 0
    else:
        print "%.09f" % dis