#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(10)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

class line2d;
class vec2d {
public:
	double x, y;
	vec2d(double, double);
	vec2d operator+(const vec2d&)const;
	vec2d operator-(const vec2d&)const;
	vec2d operator*(double)const;
	vec2d operator/(double)const;
	bool operator==(const vec2d&)const;
	bool operator!=(const vec2d&)const;
	double norm() const;
	static double inner_product(const vec2d&, const vec2d&);
	static double cros_product(const vec2d&, const vec2d&);
	static double argument(const vec2d&, const vec2d&, bool = true);
	static double distance(const vec2d&, const vec2d&);
	static vec2d projection(const vec2d&, const vec2d&);
	static vec2d reflection(const vec2d&, const line2d&);
};
class line2d {
public:
	vec2d v0, v1;
	line2d(const vec2d&, const vec2d&);
	double length()const;
	static vec2d cross_point(const line2d&, const line2d&);
	static bool is_cross(const line2d&, const line2d&);
	static double distance(const vec2d&, const line2d&);
	static double distance(const line2d&, const line2d&);
};
vec2d::vec2d(double x, double y) :x(x), y(y) {}
vec2d vec2d::operator+(const vec2d&v)const {
	return vec2d(x + v.x, y + v.y);
}
vec2d vec2d::operator-(const vec2d&v)const {
	return vec2d(x - v.x, y - v.y);
}
vec2d vec2d::operator*(double k)const {
	return vec2d(x * k, y * k);
}
vec2d vec2d::operator/(double k)const {
	return vec2d(x / k, y / k);
}
bool vec2d::operator==(const vec2d&v)const {
	return x == v.x && y == v.y;
}
bool vec2d::operator!=(const vec2d&v)const {
	return !operator== (v);
}
double vec2d::norm() const {
	return sqrt(x * x + y * y);
}
double vec2d::inner_product(const vec2d&v0, const vec2d&v1) {
	return v0.x * v1.x + v0.y * v1.y;
}
double vec2d::cros_product(const vec2d&v0, const vec2d&v1) {
	return v0.x * v1.y - v0.y * v1.x;
}
double vec2d::argument(const vec2d&v0, const vec2d&v1, bool is_signed) {
	double ret = atan2(cros_product(v0, v1), inner_product(v0, v1));
	return is_signed ? ret : abs(ret);
}
double vec2d::distance(const vec2d&v0, const vec2d&v1) {
	return hypot(v1.x - v0.x, v1.y - v0.y);
}
vec2d vec2d::projection(const vec2d&scr, const vec2d&v) {
	double n = scr.norm();
	return scr * vec2d::inner_product(scr, v) / n / n;
}
vec2d vec2d::reflection(const vec2d&v, const line2d&l) {
	return (projection(vec2d(l.v1 - l.v0), vec2d(v - l.v0)) + l.v0) * 2 - v;
}
line2d::line2d(const vec2d&v0, const vec2d&v1) :v0(v0), v1(v1) {}
double line2d::length()const {
	return vec2d::distance(v0, v1);
}
vec2d line2d::cross_point(const line2d&l0, const line2d&l1) {
	return vec2d(((l0.v1.x * l0.v0.y - l0.v0.x * l0.v1.y) * (l1.v1.x - l1.v0.x) - (l1.v1.x * l1.v0.y - l1.v0.x * l1.v1.y) * (l0.v1.x - l0.v0.x)) / ((l0.v1.x - l0.v0.x) * (l1.v1.y - l1.v0.y) - (l1.v1.x - l1.v0.x) * (l0.v1.y - l0.v0.y)), ((l0.v1.x * l0.v0.y - l0.v0.x * l0.v1.y) * (l1.v1.y - l1.v0.y) - (l1.v1.x * l1.v0.y - l1.v0.x * l1.v1.y) * (l0.v1.y - l0.v0.y)) / ((l0.v1.x - l0.v0.x) * (l1.v1.y - l1.v0.y) - (l1.v1.x - l1.v0.x) * (l0.v1.y - l0.v0.y)));
}
bool line2d::is_cross(const line2d&l0, const line2d&l1) {
	vec2d cross = cross_point(l0, l1);
	if (std::isnan(cross.x) && std::isnan(cross.y)) {
		double dis_sum = vec2d::distance(l0.v0, l0.v1) + vec2d::distance(l1.v0, l1.v1);
		double dis_max = max({ vec2d::distance(l0.v0, l0.v1),vec2d::distance(l0.v0, l1.v0),vec2d::distance(l0.v0, l1.v1),vec2d::distance(l0.v1, l1.v0),vec2d::distance(l0.v1, l1.v1),vec2d::distance(l1.v0, l1.v1) });
		return dis_max < dis_sum || abs(dis_max - dis_sum) < EPS;
	} else if (std::isinf(cross.x) || std::isinf(cross.y)) {
		return false;
	} else {
		vec2d v_l0 = l0.v1 - l0.v0;
		vec2d cross_l0 = cross - l0.v0;
		double ks0 = v_l0.x != 0 ? cross_l0.x / v_l0.x : cross_l0.y / v_l0.y;
		vec2d v_l1 = l1.v1 - l1.v0;
		vec2d cross_l1 = cross - l1.v0;
		double ks1 = v_l1.x != 0 ? cross_l1.x / v_l1.x : cross_l1.y / v_l1.y;
		return 0 <= ks0 && ks0 <= 1 && 0 <= ks1 && ks1 <= 1;
	}
}
double line2d::distance(const vec2d&v, const line2d&l) {
	line2d l_ref(v, vec2d::reflection(v, l));
	return is_cross(l, l_ref) ? l_ref.length() / 2 : min({ vec2d::distance(v,l.v0),vec2d::distance(v,l.v1) });
}
double line2d::distance(const line2d&l0, const line2d&l1) {
	return is_cross(l0, l1) ? 0 : min({ distance(l0.v0,l1),distance(l0.v1,l1),distance(l1.v0,l0),distance(l1.v1,l0) });
}

signed main() {
	SETP;
	int q = in();
	REP(i, q) {
		double xp0 = in(), yp0 = in(), xp1 = in(), yp1 = in(), xp2 = in(), yp2 = in(), xp3 = in(), yp3 = in();
		vec2d p0(xp0, yp0), p1(xp1, yp1), p2(xp2, yp2), p3(xp3, yp3);
		line2d s1(p0, p1), s2(p2, p3);
		cout << line2d::distance(s1, s2) << endl;
	}
}


Measured memory_bytes: 3348