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 <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for(int i = (int)s; i < (int)(e); ++i)

#define X real()
#define Y imag()
#define x(p) real(p)
#define y(p) imag(p)
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define prev(P, i) P[(i-1+P.size())%P.size()]

const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);

typedef double D;
typedef complex<D> P;
namespace std{
  bool operator < (const P& a, const P& b) {
    return x(a) != x(b) ? x(a) < x(b) : y(a) < y(b);
  }
}

D dot(const P& a, const P& b) {
  return x(conj(a)*b);
}
D cross(const P& a, const P& b) {
  return y(conj(a)*b);
}

struct L : public vector<P> {
  L(const P&a, const P& b) {
    push_back(a);
    push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; D r;
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if(cross(b, c) > 0) return +1; //ccw
  if(cross(b, c) < 0) return -1; //cw
  if(dot(b, c) < 0)   return +2; //c-a-b on line
  if(norm(b) < norm(c)) return -2; //a-b-c on line
  return 0;
}

P projection(const L& l, const P& p) {
  D t = dot(p - l[0], l[0] - l[1]) / norm(l[0]- l[1]);
  return l[0] + t * (l[0] - l[1]);
}
P refrection(const L& l, const P& p) {
  return p + 2.0 * (projection(l, p) - p);
}

bool intersectSP(const L& l, const P& p) {
  return abs(l[0]-p) + abs(l[1]-p) - abs(l[1] - l[0]) < EPS;
}

bool intersectSS(const L& a, const L& b) {
  return ccw(a[0], a[1], b[0]) * ccw(a[0], a[1], b[1]) <= 0
    && ccw(b[0], b[1], a[0]) * ccw(b[0], b[1], a[1]) <= 0;
}
P crossP(const L& a, const L& b) {
  D x = cross(a[1]-a[0], b[1]-b[0]);
  D y = cross(a[1]-a[0], a[1]-b[0]);
  if(abs(x) < EPS && abs(y) < EPS) return a[0];
  return b[0] + y / x * (b[1]-b[0]);
}
D distSP(const L& l, const P& p) {
  const P r = projection(l, p);
  if(intersectSP(l, r)) return abs(r - p);
  return min(abs(l[0]-p), abs(l[1]-p));
}
D distSS(const L& a, const L& b) {
  if(intersectSS(a, b)) return 0;
  return min({distSP(a, b[0]), distSP(a, b[1]), distSP(b, a[0]), distSP(b, a[1])});
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    vector<P> ps(4);
    rep(i, 4) {
      D x, y;
      cin >> x >> y;
      ps[i] = {x, y};
    }
    vector<L> ls;
    rep(i, 2) ls.push_back({ps[2*i], ps[2*i+1]});
    cout << fixed << setprecision(20);
    cout << distSS(ls[0], ls[1]) << endl;
  }
  return 0;
}