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:
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

def in_sec(a, b, c):
    return min(a, b) <= c <= max(a, b)
def dist(xp, yp, xq, yq):
    return math.sqrt((xq - xp) ** 2 + (yp - yq) ** 2)
def min_d(x, y, xp, yp, xq, yq):
    vx, vy = [xp - xq, yp - yq]
    vx1, vy1 = [x - xp, y - yp]
    vx2, vy2 = [x - xq, y - yq]
    if (vx1 * vx + vy1 * vy) * (vx2 * vx + vy2 * vy) < 0:
        a, b, c = [yq - yp, xp - xq, xp * (yp - yq) + yp * (xq - xp)]
        return abs(a * x + b * y + c) / math.sqrt(a ** 2 + b ** 2)
    return min(dist(x, y, xp, yp), dist(x, y, xq, yq))

q = input()

for loop in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(float, raw_input().split())
    #(y1 - y0)(x - x0) = (x1 - x0)(y - y0)
    a1, b1, c1 = [y1 - y0, x0 - x1, x0 * (y1 - y0) - y0 * (x1 - x0)]
    a2, b2, c2 = [y3 - y2, x2 - x3, x2 * (y3 - y2) - y2 * (x3 - x2)]
    det = a1 * b2 - b1 * a2
    if det == 0:
        dx, dy = [x2 - x0, y2 - y0]
        if dx * a1 + dy * b1 == 0 and \
            not(max(x0, x1) < min(x2, x3) or max(x2, x3) < min(x0, x1) \
            or max(y0, y1) < min(y2, y3) or max(y2, y3) < min(y0, y1)):
            print 0
            continue
    else:
        xdet = c1 * b2 - c2 * b1
        ydet = c2 * a1 - c1 * a2
        if in_sec(det * x0, det * x1, xdet) and in_sec(det * y0, det * y1, ydet) \
            and in_sec(det * x2, det * x3, xdet) and in_sec(det * y2, det * y3, ydet):
            print 0
            continue

    ans = min(min_d(x0, y0, x2, y2, x3, y3), min_d(x1, y1, x2, y2, x3, y3), 
        min_d(x2, y2, x0, y0, x1, y1), min_d(x3, y3, x0, y0, x1, y1))
    print "%.10f" % ans