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>

#define rep(i, a, b) for (int i = a, i##end = b; i <= i##end; ++i)
#define per(i, a, b) for (int i = a, i##end = b; i >= i##end; --i)
#define rep0(i, a) for (int i = 0, i##end = a; i < i##end; ++i)
#define per0(i, a) for (int i = (int)a-1; ~i; --i)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)
#define x first
#define y second
#define enter putchar('\n')

typedef long long ll;
typedef double DB;

const DB eps = 1e-12;

int sgn(DB x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1); }

struct Point {
	DB x, y;
	Point(DB x = 0, DB y = 0) : x(x), y(y) {}
	Point operator + (Point a) { return Point(x + a.x, y + a.y); }
	Point operator - (Point a) { return Point(x - a.x, y - a.y); }
	Point operator - () { return Point(-x, -y); }
	friend Point operator * (DB k, Point a) { return Point(k * a.x, k * a.y); }
	DB operator % (Point a) { return x * a.x + y * a.y; }
	DB operator / (Point a) { return x * a.y - y * a.x; }
	operator DB() { return sqrt(x*x + y*y); }
};

Point gp() { Point a; scanf("%lf%lf", &a.x, &a.y); return a; }
void wp(Point a) { printf("%.10lf %.10lf ", a.x, a.y); }

struct Poly {
	std::vector<Point> a;
	Poly(int n = 0) { a.resize(n); rep0(i, n) a[i] = gp(); }
	Point &operator [] (int i) { int n = a.size(); return a[i >= n ? i-n : i]; }
};

Point Proj(Point P, Point P1, Point P2) { // Projection
	Point v = P2-P1; DB t = (P-P1)%v / (v%v);
	return P1 + t*v;
}

int Direct1(Point P, Point P1, Point P2) { return sgn((P1-P)%(P2-P)); }
int Direct2(Point P, Point P1, Point P2) { return sgn((P1-P)/(P2-P)); }

bool IsSegInter(Point P1, Point P2, Point Q1, Point Q2) {
	if (min(P1.x, P2.x) <= max(Q1.x, Q2.x) && max(P1.x, P2.x) >= min(Q1.x, Q2.x) && min(P1.y, P2.y) <= max(Q1.y, Q2.y) && max(P1.y, P2.y) >= min(Q1.y, Q2.y))
		if (Direct2(P1, P2, Q1) * Direct2(P1, P2, Q2) <= 0 && Direct2(Q1, Q2, P1) * Direct2(Q1, Q2, P2) <= 0) return 1;
	return 0;
}

Point GetSegInter(Point P1, Point P2, Point Q1, Point Q2) {
	Point v = P2-P1, w = Q2-Q1; DB t = (Q1-P1)/w / (v/w);
	return P1 + t*v;
}

DB PointLineDist(Point P, Point P1, Point P2) {
	return DB(Proj(P, P1, P2)-P);
}

DB PointSegDist(Point P, Point P1, Point P2) {
	if (Direct1(P1, P2, P) * Direct1(P2, P1, P) >= 0) return PointLineDist(P, P1, P2);
	return min(DB(P-P1), DB(P-P2));
}

DB SegDist(Point P1, Point P2, Point Q1, Point Q2) {
	if (IsSegInter(P1, P2, Q1, Q2)) return 0;
	return min(min(PointSegDist(P1, Q1, Q2), PointSegDist(P2, Q1, Q2)), min(PointSegDist(Q1, P1, P2), PointSegDist(Q2, P1, P2)));
}

int q;

int main() {
	scanf("%d", &q);
	while (q--) {
		Point P1 = gp(), P2 = gp(), Q1 = gp(), Q2 = gp();
		printf("%.10lf\n", SegDist(P1, P2, Q1, Q2));
		//wp(GetSegInter(P1, P2, Q1, Q2)); enter;
		//printf("%d\n", IsInter(P1, P2, Q1, Q2));
		//wp(Proj(P, P1, P2)); enter;
	}
	return 0;
}