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 <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

// common
#define X real()
#define Y imag()

using Vector2 = complex<double>;
using Line = pair<Vector2, Vector2>;
using Segment = pair<Vector2, Vector2>;
const double EPS = 1e-10;
const double PI = 3.14159265359;

bool equals(double a, double b){
    if(abs(a - b) < EPS){
        return true;
    }
    else{
        return false;
    }
}

// struct

struct Circle{
    Vector2 c;
    double r;
    Circle(Vector2 c, double r){
        this->c = c;
        this->r = r;
    }
};

// Vector2
double dot(Vector2 a, Vector2 b){
    return (a.X * b.X + a.Y * b.Y);
}

double cross(Vector2 a, Vector2 b){
    return (a.X * b.Y - a.Y * b.X);
}

double distLP(Line l, Vector2 p){
    return abs(cross(l.second - l.first, p - l.first) / abs(l.second - l.first));
}

// ccw
int ccw(Vector2 p1, Vector2 p2, Vector2 p3){
    Vector2 a = p2 - p1;
    Vector2 b = p3 - p1;
    double dotValue = dot(a, b);
    double crossValue = cross(a, b);
    if(crossValue > EPS) return 1;  // anticlockwise
    if(crossValue < -EPS) return -1;    // clockwise
    if(dotValue < -EPS) return 2;   // p2-p1-p3
    if(norm(a) < norm(b)) return -2;    // p1-p2-p3
    return 0;   // p1-p3-p2
}

// line segment

bool intersect(Segment s1, Segment s2){
    if(ccw(s1.first, s2.first, s2.second) * ccw(s1.second, s2.first, s2.second) > 0){
        return false;
    }
    if(ccw(s2.first, s1.first, s1.second) * ccw(s2.second, s1.first, s1.second) > 0){
        return false;
    }
    return true;
}

double distSP(Segment s, Vector2 p){
    if(dot(s.second - s.first, p - s.first) < 0.0) return abs(p - s.first);
    if(dot(s.first - s.second, p - s.second) < 0.0) return abs(p - s.second);
    return distLP(s, p);
}

double dist(Segment s1, Segment s2){
    if(intersect(s1, s2)){
        return 0.0;
    }
    double a = min(distSP(s1, s2.first), distSP(s1, s2.second));
    double b = min(distSP(s2, s1.first), distSP(s2, s1.second));
    return min(a, b);
}

int main(){

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        Segment s1(Vector2(x0, y0), Vector2(x1, y1));
        Segment s2(Vector2(x2, y2), Vector2(x3, y3));
        double ans = dist(s1, s2);
        cout << fixed << setprecision(9) << ans << endl;
    }

    return 0;
}