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 <bits/stdc++.h>
using namespace std;

constexpr double EPS = 1e-10;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
typedef pair<Point, double> Circle;
typedef vector<Point> Polygon;
double dot(Vector a, Vector b){
	return real(a) * real(b) + imag(a) * imag(b);
}
double cross(Vector a, Vector b){
	return real(a) * imag(b) - imag(a) * real(b);
}
Point project(Line l, Point p){
	Vector base = l.second - l.first;
	base /= abs(base);
	double r = dot(p - l.first, base);
	return l.first + r * base;
}
Point reflect(Line l, Point p){
	return p + (project(l, p) - p) * 2.0;
}
int ccw(Point p0, Point p1, Point p2){
	Vector v = p1 - p0, w = p2 - p0;
	if(cross(v, w) > EPS) return 1; // COUNTER_CLOCKWISE
	if(cross(v, w) < -EPS) return -1; // CLOCKWISE
	if(dot(v, w) < -EPS) return 2; // ONLINE p2 - p0 - p1
	if(norm(v) + EPS < norm(w)) return -2; // ONLINE p0 - p1 - p2
	return 0; // ONLINE p0 - p1 - p2
}
bool isOrthogonal(Vector v1, Vector v2){
	double t = abs(dot(v1, v2));
	return t <= EPS;
}
bool isParallel(Vector v1, Vector v2){
	double t = abs(cross(v1, v2));
	return t <= EPS;
}
bool intersect(Segment s1, Segment s2){
	int t = ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second);
	int u = ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second);
	return (t == 0 || t == -1 || t == -4) && (u == 0 || u == -1 || u == -4);
}
Point getCrossPoint(Segment s1, Segment s2){
	assert(intersect(s1, s2));
	assert(!isParallel(s1.second - s1.first, s2.second - s2.first));
	Vector base = s2.second - s2.first;
	double d1 = abs(cross(base, s2.first - s1.first));
	double d2 = abs(cross(base, s2.first - s1.second));
	return s1.first + (s1.second - s1.first) * d1 / (d1 + d2);
}
double getDistancePL(Point p, Line l){
	return abs(cross(p - l.first, l.second - l.first)) / abs(l.second - l.first);
}
double getDistancePS(Point p, Segment s){
	if(dot(s.second - s.first, p - s.first) < 0.0) return abs(p - s.first);
	if(dot(s.first - s.second, p - s.second) < 0.0) return abs(p - s.second);
	return getDistancePL(p, Line(s));
}
double getDistanceSS(Segment s1, Segment s2){
	if(intersect(s1, s2)) return 0.0;
	return min({getDistancePS(s2.first, s1), getDistancePS(s2.second, s1), getDistancePS(s1.first, s2), getDistancePS(s1.second, s2)});
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	while(q--){
		double x[4], y[4];
		for(int i=0; i<4; ++i) cin >> x[i] >> y[i];
		Point p0(x[0], y[0]), p1(x[1], y[1]), p2(x[2], y[2]), p3(x[3], y[3]);
		cout << setprecision(14) << getDistanceSS(Segment(p0, p1), Segment(p2, p3)) << "\n";
	}
}