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<iomanip>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
using namespace std;

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}
	Point operator + (Point p) {
		return Point(x + p.x, y + p.y); 
	}
	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double a) {
		return Point(a * x, a * y);
	}
	Point operator / (double a) {
		return Point(x / a, y / a);
	}

	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}

	bool operator < (const Point &p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

double getDistanceSP(Point p, Point p1, Point p2) {
	if (dot(p - p1, p2 - p1) < 0.0)return (p - p1).abs();
	else if (dot(p - p2, p1 - p2) < 0.0)return (p - p2).abs();
	else return  fabs(cross(p2 - p1, p - p1)) / (p2 - p1).abs();
}


double angle(Vector a, Vector b) {
	if (cross(a, b) >= 0.0)return acos(dot(a, b) / a.abs() / b.abs());
	else return (-1) * acos(dot(a, b) / a.abs() / b.abs());
}

bool doIntersect(Point p1, Point p2, Point p3, Point p4) {
	if ((equals(fabs(angle(p2 - p1, p4 - p1)), 0) || equals(fabs(angle(p2 - p1, p4 - p1)), M_PI)) && (equals(fabs(angle(p2 - p1, p3 - p1)), 0) || equals(fabs(angle(p2 - p1, p3 - p1)), M_PI)))return false;
	else if (angle(p3 - p1, p4 - p1) >= angle(p3 - p1, p2 - p1) && angle(p3 - p1, p2 - p1) >= 0.0 && angle(p2 - p3, p1 - p3) >= angle(p2 - p3, p4 - p3) && angle(p2 - p3, p4 - p3) >= 0.0)return true;
	else if (angle(p3 - p2, p4 - p2) >= angle(p3 - p2, p1 - p2) && angle(p3 - p2, p1 - p2) >= 0.0 && angle(p1 - p3, p2 - p3) >= angle(p1 - p3, p4 - p3) && angle(p1 - p3, p4 - p3) >= 0.0)return true;
	else return false;
}

double getDistanceSS(Point p1, Point p2, Point p3, Point p4) {
	if (doIntersect(p1, p2, p3, p4))return 0;
	else return min({ getDistanceSP(p4, p1, p2), getDistanceSP(p3, p1, p2), getDistanceSP(p1, p3, p4), getDistanceSP(p2, p3, p4) });
}

int main() {
    int i, q;
	double x1, x2, x3, x4, y1, y2, y3, y4;
	Point ans;
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		Point p1(x1, y1), p2(x2, y2), p3(x3, y3), p4(x4, y4);
		cout << setprecision(15) << getDistanceSS(p1, p2, p3, p4) << endl;
	}
	return 0;
}