/* Header {{{ */
#include <bits/stdc++.h>
using namespace std;

typedef long long readtype;
typedef long long var;
typedef long double let;

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}

#ifdef LOCAL_LOGGER
#define logger(...) fprintf(stderr, __VA_ARGS__)
#define abortif(v, ...) if (v) {logger("Error in Line %d, Function '%s()'.\nInfo: ", __LINE__, __FUNCTION__); logger(__VA_ARGS__); exit(0);}
#else
#define logger(...);
#define abortif(v, ...);
#endif
/* }}} */

const let EPS = 1e-8;

int sign(let x) { return (x < -EPS) ? -1 : (x > EPS ? 1 : 0);}

struct Point {
  let x, y;

  Point operator ~() {
    return (Point) {x, -y};
  }
  friend Point operator + (Point a, Point b) {
    return (Point) {a.x + b.x, a.y + b.y};
  }
  friend Point operator - (Point a, Point b) {
    return (Point) {a.x - b.x, a.y - b.y};
  }
  Point operator * (let k) { return (Point) {x * k, y * k}; }

  friend let Times(Point a, Point b) {
    return a.x * b.y - a.y * b.x;
  }

  let dist() {
    return sqrt(x * x + y * y);
  }

  friend let Dist(Point a, Point b) {
    return (a - b).dist();
  }

  Point Rotate(Point k) {
    let z = k.dist();
    return Rotate(k.y / z, k.x / z);
  }

  Point Rotate(let sink, let cosk) {
    return (Point) {
      x * cosk - y * sink, x * sink + y * cosk
    };
  }
};

typedef Point Vec;

struct Segment {
  Point s, e;
  Vec v;
  Segment() {}
  Segment(Point a, Point b) {
    s = a, e = b;
    v = b - a;
  }
  Segment(Point a, Point b, Vec c) {
    s = a, e = b, v = c;
  }

  Segment operator - (Vec k) {
    return (Segment) {
      s - k, e - k, v
    };
  }

  Segment Rotate(Vec k) {
    let z = k.dist();
    return Rotate(k.y / z, k.x / z);
  }

  Segment Rotate(let sink, let cosk) {
    return (Segment) {
      s.Rotate(sink, cosk), e.Rotate(sink, cosk), v.Rotate(sink, cosk)
    };
  }

  friend let Dist(Segment a, Point b) {
    let ar = a.v.dist();
    Point c = (b - a.s).Rotate(~a.v);
    if (sign(c.x) >= 0 && sign(c.x - ar) <= 0) return fabs(c.y);
    return min(c.dist(), Dist(c, (Point) {ar, 0}));
  }

  friend bool Intersection(Segment a, Segment b) {
    let ar = a.v.dist();
    Segment c = (b - a.s).Rotate(~a.v);

    int tcs = sign(Times(c.s, (Point) {ar, 0})),
        tce = sign(Times(c.e, (Point) {ar, 0}));

    if (tcs == 0 && tce == 0) {
      if (sign(max(c.s.x, c.e.x)) < 0 ||
          sign(min(c.s.x, c.e.x) - ar) > 0) return false;
      return true;
    }

    if (tcs == tce) return false;

    Point i = c.e - c.v * (c.e.y / c.v.y);
    if (sign(i.x) < 0 || sign(i.x - ar) > 0) return false;
    return true;
  }

  friend let Dist(Segment a, Segment b) {
    if (Intersection(a, b)) return 0;

    Point ar = (Point) {a.v.dist(), 0};
    Segment c = (b - a.s).Rotate(~a.v);

    let res = min(Dist(b, a.s), Dist(b, a.e));
    if (sign(c.s.x) >= 0 && sign(c.s.x - ar.x) <= 0)
      res = min(res, fabs(c.s.y));
    if (sign(c.e.x) >= 0 && sign(c.e.x - ar.x) <= 0)
      res = min(res, fabs(c.e.y));
    return res;
  }
};

Point ReadPoint() {
  Point t;
  scanf("%Lf%Lf", &t.x, &t.y);
  return t;
}

int main() {
// #ifndef ONLINE_JUDGE
//   freopen("CGL_2_D.in", "r", stdin);
//   freopen("CGL_2_D.out", "w", stdout);
// #endif
// #ifdef LOCAL_LOGGER
//   freopen("CGL_2_D.log", "w", stderr);
// #endif
  int q = read();
  while (q--) {
    Point p0 = ReadPoint(), p1 = ReadPoint(), p2 = ReadPoint(), p3 = ReadPoint();
    Segment s1 = (Segment) {p0, p1}, s2 = (Segment) {p2, p3};
    printf("%.8Lf\n", Dist(s1, s2));
  }
  return 0;
}

/* ==== Makefile ==== {{{
CompileAndRun:
	make Compile
	make Run

Compile:
	g++ -o CGL_2_D CGL_2_D.cpp -g -Wall -DLOCAL_LOGGER

CompileUF:
	g++ -o CGL_2_D CGL_2_D.cpp -g -Wall -DLOCAL_LOGGER -fsanitize=undefined

Run:
	./CGL_2_D < CGL_2_D.in > CGL_2_D.out
==================
}}} */



Measured memory_bytes: 3244