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 <cmath>
using namespace std;

inline double add(double a, double b){
    return abs(a+b)<(1e-10)*(abs(a)+abs(b)) ? 0.0 : a+b;
}

struct vec{
    double x,y;
    vec operator-(vec b){
        return (vec){add(x,-b.x),add(y,-b.y)};
    }
    vec operator+(vec b){
        return (vec){add(x,b.x),add(y,b.y)};
    }
    vec operator*(double d){
        return (vec){x*d,y*d};
    }
    double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    double norm(){
        return sqrt(x*x+y*y);
    }
};

const double eps = 0.0000001;


int ccw(vec& a, vec& b, vec& c){
    vec ab = b-a, ac = c-a;
    double o = ab.cross(ac);
    if(o>0) return 1; //CCW
    if(o<0) return -1; //CW
    if(ab.dot(ac)<0){
        return 2; //C-A-B
    }else{
        if(ab.dot(ab)<ac.dot(ac)){
            return -2; //A-B-C
        }else{
            return 0; //A-C-B
        }
    }
}

bool isInterSection(vec (&p)[4]){
    switch(ccw(p[0],p[1],p[2])*ccw(p[0],p[1],p[3])){
        case -1:
        case -4:
        case 0:
            break;
        default:
            return false;
    }
    switch(ccw(p[2],p[3],p[0])*ccw(p[2],p[3],p[1])){
        case -1:
        case -4:
        case 0:
            break;
        default:
            return false;
    }
   return true;
}

vec interSection(vec (&p)[4]){
    vec p23=p[3]-p[2],p02=p[2]-p[0],p01=p[1]-p[0];
    double k = p23.cross(p02)/p23.cross(p01);
    return p[0]+p01*k;
}

double dist(vec (&p)[4]){
    if(isInterSection(p)) return 0;
    double dist =1e5;
    vec P;
    P=p[0]+(p[1]-p[0])*((p[1]-p[0]).dot(p[2]-p[0])/(p[1]-p[0]).dot(p[1]-p[0]));
    if(!ccw(p[0],p[1],P)){
        dist = min(dist,(P-p[2]).norm());
    }
    P=p[0]+(p[1]-p[0])*((p[1]-p[0]).dot(p[3]-p[0])/(p[1]-p[0]).dot(p[1]-p[0]));
    if(!ccw(p[0],p[1],P)){
        dist = min(dist,(P-p[3]).norm());
    }
    P=p[2]+(p[3]-p[2])*((p[3]-p[2]).dot(p[0]-p[2])/(p[3]-p[2]).dot(p[3]-p[2]));
    if(!ccw(p[2],p[3],P)){
        dist = min(dist,(P-p[0]).norm());
    }
    P=p[2]+(p[3]-p[2])*((p[3]-p[2]).dot(p[1]-p[2])/(p[3]-p[2]).dot(p[3]-p[2]));
    if(!ccw(p[2],p[3],P)){
        dist = min(dist,(P-p[1]).norm());
    }
    dist = min(dist,(p[2]-p[0]).norm());
    dist = min(dist,(p[2]-p[1]).norm());
    dist = min(dist,(p[3]-p[0]).norm());
    dist = min(dist,(p[3]-p[1]).norm());
    return dist;
}

int main(void){
    vec p[4];
    int q;
    cin >> q;
    cout.precision(10);
    cout << fixed;
    while(q--){
        for(auto& v : p) cin >> v.x >> v.y;
        cout << dist(p) << endl;
    }
    return 0;
}