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 <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

template<class T>
struct Vec2
{
	Vec2(){}
	Vec2(T _x, T _y) : x(_x), y(_y) {}

	Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
	Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
	Vec2 operator*(T s) const { return Vec2(x*s, y*s); }
	Vec2 operator/(T s) const { return Vec2(x/s, y/s); }
	T dot(const Vec2& rhs) const { return x*rhs.x + y*rhs.y; }
	T cross(const Vec2& rhs) const { return x*rhs.y - y*rhs.x; }
	T sqlength() const { return x*x + y*y; }
	double length() const { return sqrt(sqlength()); }
	bool operator<(const Vec2& rhs) const
	{
		if (x != rhs.x) return x < rhs.x;
		return y < rhs.y;
	}

	T x;
	T y;
};

template<class T>
T cross(const Vec2<T> &O, const Vec2<T> &A, const Vec2<T> &B)
{
	return (A - O).cross(B - O);
}

template<class T>
bool IsIntSegments(const Vec2<T>& A1, const Vec2<T>& A2, const Vec2<T>& B1, const Vec2<T>& B2)
{
	return (cross(A1, A2, B1)*cross(A1, A2, B2) < 0 && cross(B1, B2, A1)*cross(B1, B2, A2) < 0);
}

template<class T>
double DistPoint2Seg(const Vec2<T>& P, const Vec2<T>& A, const Vec2<T>& B)
{
	if ((B - A).dot(P - A) < 0) return (P - A).length();
	if ((A - B).dot(P - B) < 0) return (P - B).length();
	return fabs(double((B - A).cross(P - A))) / (B - A).length();
}

int main()
{
	typedef Vec2<long long> Vec;

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		Vec P[4];
		for (int j = 0; j < 4; j++) {
			cin >> P[j].x >> P[j].y;
		}

		if (IsIntSegments(P[0], P[1], P[2], P[3])) {
			puts("0");
			continue;
		}

		double d1 = DistPoint2Seg(P[0], P[2], P[3]);
		double d2 = DistPoint2Seg(P[1], P[2], P[3]);
		double d3 = DistPoint2Seg(P[2], P[0], P[1]);
		double d4 = DistPoint2Seg(P[3], P[0], P[1]);
		printf("%.10f\n", min(d1, min(d2, min(d3, d4))));
	}
	return 0;
}