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:
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;
struct Point { long double px, py; };
struct Segment { Point p1, p2; };
Point Minus(Point a, Point b) { Point G; G.px = a.px - b.px; G.py = a.py - b.py; return G; }
long double Abs(Point a) { return sqrt(a.px*a.px + a.py*a.py); }
long double norm(Point a) { return a.px*a.px + a.py*a.py; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int ccw(Point p0, Point p1, Point p2) {
	Point a = Minus(p1, p0), b = Minus(p2, p0);
	if (crs(a, b) > 1e-10) return 1;
	if (crs(a, b) < -1e-10) return -1;
	if (dot(a, b) < -1e-10) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool its(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool its(Segment s1, Segment s2) {
	return its(s1.p1, s1.p2, s2.p1, s2.p2);
}
long double dst(const Segment& a, const Point& b) {
	if (dot(Minus(a.p2, a.p1), Minus(b, a.p1)) < 0.0) return Abs(Minus(b, a.p1));
	if (dot(Minus(a.p1, a.p2), Minus(b, a.p2)) < 0.0) return Abs(Minus(b, a.p2));
	return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1)));
}
int main() {
	Point P1, P2, P3, P4; Segment M1, M2;
	int T; cin >> T;
	for (int i = 0; i < T; i++) {
		cin >> P1.px >> P1.py >> P2.px >> P2.py;
		cin >> P3.px >> P3.py >> P4.px >> P4.py;
		M1.p1 = P1; M1.p2 = P2; M2.p1 = P3; M2.p2 = P4;
		long double res = min(dst(M1, P3), dst(M1, P4));
		res = min(res, min(dst(M2, P1), dst(M2, P2)));
		if (its(M1, M2) == true) { res = 0.0; }
		cout << fixed << setprecision(1919) << res << endl;
	}
	return 0;
}