#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class Vec;
Vec operator/(const Vec& v, const double& divisor);
Vec operator*(const double& scale, const Vec& v);

class Vec {
  using F = double;
  vector<F> container;

 public:
  Vec(size_t size) : container(size) {}
  Vec(initializer_list<F> elements)
      : container(elements.begin(), elements.end()) {}
  size_t dim() const { return container.size(); }
  F& operator[](const size_t size) { return container.at(size); }
  const F& operator[](const size_t size) const { return container.at(size); }
  Vec operator+(const Vec& other) const {
    Vec ret(*this);
    for (size_t i = 0; i < dim(); i++) ret[i] += other[i];
    return ret;
  }
  Vec operator-(const Vec& other) const { return (*this) + (-other); }
  Vec operator-() const { return -1.0 * (*this); }
  F inner(const Vec& other) const {
    F acc = 0;
    for (size_t i = 0; i < dim(); i++) {
      acc += (*this)[i] * other[i];
    }
    return acc;
  }
  F norm() const { return sqrt(inner(*this)); }
  Vec unit() const { return (*this) / this->norm(); }
  F ccw(const Vec& other) const {
    return (*this)[0] * other[1] - other[0] * (*this)[1];
  }
  Vec normal() const { return Vec({-(*this)[1], (*this)[0]}); }
};
Vec operator/(const Vec& v, const double& divisor) { return 1.0 / divisor * v; }
Vec operator*(const double& scale, const Vec& v) {
  Vec ret(v);
  for (size_t i = 0; i < ret.dim(); i++) ret[i] *= scale;
  return ret;
}

class Line {
  Vec m_grad;
  double m_bias;

 public:
  Line(const Vec& grad, double bias) : m_grad(grad), m_bias(bias) {}
  static Line fromPoints(const Vec& p0, const Vec& p1) {
    Vec d = p0 - p1;
    Vec g({-d[1], d[0]});
    return Line(g, g.inner(p0));
  }
  const Vec& grad() const { return m_grad; }
  double bias() const { return m_bias; }
  double dist(const Vec& p) const {
    return abs(m_grad.inner(p) - m_bias) / m_grad.norm();
  }
  Vec projection(const Vec& p) const {
    const Vec g = m_grad.unit();
    const Vec h({-g[1], g[0]});
    return m_bias / m_grad.norm() * g + h.inner(p) * h;
  }
};

class Segment {
  const Vec m_start;
  const Vec m_end;

 public:
  Segment(const Vec& start, const Vec& end) : m_start(start), m_end(end) {}
  bool intersect(const Segment& other, const double eps) const {
    const Vec u = other.m_start - m_start, w = other.m_end - m_start;
    const Vec v0 = m_end - m_start, v1 = other.m_end - other.m_start;

    const double vn = v0.norm();
    double u_v = v0.inner(u) / vn;
    double w_v = v0.inner(w) / vn;
    if (abs(abs(u_v / u.norm()) - 1) < eps &&
        abs(abs(w_v / w.norm()) - 1) < eps) {
      if (u_v > w_v) {
        swap(u_v, w_v);
      }
      return !(u_v > vn + eps || w_v < -eps);
    }
    bool cond1 =
        v0.ccw(other.m_start - m_start) * v0.ccw(other.m_end - m_start) < eps;
    bool cond2 =
        v1.ccw(m_start - other.m_start) * v1.ccw(m_end - other.m_start) < eps;
    return cond1 && cond2;
  }
  Vec direction() const { return m_end - m_start; }
  double dist(const Vec& p) const {
    const Vec dir = direction();
    const Vec d = dir.unit();
    const Vec q = p - m_start;
    const double a = d.inner(q);
    if (a < 0) {
      return (m_start - p).norm();
    } else if (dir.norm() < a) {
      return (m_end - p).norm();
    } else {
      return abs(d.normal().inner(q));
    }
  }
  double dist(const Segment& other) const {
    if (intersect(other, 0.0)) {
      return 0.0;
    }
    return min(min(dist(other.m_start), dist(other.m_end)),
               min(other.dist(m_start), other.dist(m_end)));
  }
};

int main() {
  int q;
  cin >> q;

  rep(i, q) {
    double x0, y0, x1, y1, x2, y2, x3, y3;
    cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    const Vec p0(Vec({x0, y0})), p1(Vec({x1, y1})), p2(Vec({x2, y2})),
        p3(Vec({x3, y3}));
    cout << fixed << setprecision(10) << Segment(p0, p1).dist(Segment(p2, p3))
         << endl;
    }
  return 0;
}



Measured memory_bytes: 3340