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 CPP):

Solution:
#ifndef ___Geometry_Library
#define ___Geometry_Library

// ------ Includes ------ //
#include <cmath>
#include <complex>
#include <utility>
#include <algorithm>

// ------ Defines ------ //
typedef long double GType;
typedef std::complex<GType> Point;
typedef std::pair<Point, Point> Segment;

// ------ Constants ------ //
const GType EPS = 1.0e-10L;

// ------ Functions Level 1 ------ //
GType dot(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).real();
}
GType cross(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).imag();
}
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point v1 = p2 - p1, v2 = p3 - p1;
	if (cross(v1, v2) > EPS) return +1;
	if (cross(v1, v2) < -EPS) return -1;
	if (dot(v1, v2) < -EPS) return +2;
	if (std::norm(v1) < std::norm(v2)) return -2;
	return 0;
}

// ------ Functions Level 2 ------ //
bool intersect(const Segment& s1, const Point& p1, bool segflag) {
	if (!segflag) return std::abs(cross(s1.second - p1, s1.first - p1)) < EPS;
	return (std::abs(s1.first - p1) + std::abs(s1.second - p1) - std::abs(s1.second - s1.first)) < EPS;
}
bool intersect(const Segment& s1, const Segment& s2, bool segflag) {
	if (!segflag) return cross(s1.second - s1.first, s2.first - s1.first) * cross(s1.second - s1.first, s2.second - s1.first) < EPS;
	return (ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second)) <= 0 && (ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second)) <= 0;
}
Point projection(const Segment& s1, const Point& p1) {
	GType mul = dot(p1 - s1.first, s1.first - s1.second) / norm(s1.first - s1.second);
	return s1.first + (s1.first - s1.second) * mul;
}
Point reflection(const Segment& s1, const Point& p1) {
	return p1 + (projection(s1, p1) - p1) * (GType)(2);
}
GType distance(const Point& p1, const Point& p2) {
	return std::abs(p2 - p1);
}
GType distance(const Segment& s1, const Point& p1, bool segflag) {
	if (!segflag) return std::abs(p1 - projection(s1, p1));
	const Point p2 = projection(s1, p1);
	if (intersect(s1, p2, true)) return std::abs(p2 - p1);
	return std::min(std::abs(s1.first - p1), std::abs(s1.second - p1));
}
GType distance(const Segment& s1, const Segment& s2, bool segflag) {
	if (intersect(s1, s2, segflag)) return 0;
	if (!segflag) return std::min(distance(s1, s2.first, false), distance(s1, s2.second, false));
	return std::min({ distance(s1, s2.first, true), distance(s1, s2.second, true), distance(s2, s1.first, true), distance(s2, s1.second, true) });
}

#endif

#include <iomanip>
#include <iostream>
using namespace std;
int q, xa, ya, xb, yb; Segment s1, s2;
int main() {
	cin >> q;
	while (q--) {
		cin >> xa >> ya >> xb >> yb; s1 = make_pair(Point(xa, ya), Point(xb, yb));
		cin >> xa >> ya >> xb >> yb; s2 = make_pair(Point(xa, ya), Point(xb, yb));
		cout << fixed << setprecision(15) << distance(s1, s2, true) << endl;
	}
	return 0;
}