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>
#define eps 1e-9
#define nmax 200
#define f(c,a,b) for(int c=a; c<=b; c++)
#define pi acos(-1)

using namespace std;
typedef double db;
struct P{
    db x, y;
    P operator - (P a){ return (P){x-a.x, y-a.y}; }
    db dot(P a){ return a.x*x + a.y*y; }
    P operator * (db a) { return (P){a*x, a*y}; }
    P operator + (P a){ return (P){x+a.x, y+a.y}; }
    P operator / (db a) { return (P) {x/a, y/a}; }
    db times(P a){ return x*a.y-y*a.x; }
    db le() { return sqrt( x*x+y*y ); }
    db le2() { return x*x+y*y; }
    P rot90(){ return (P){-y,x}; }
    db rad(P a) { return atan2(times(a),dot(a)); }
    void pri(){ printf("%.10lf %.10lf\n", x, y); }
    void swap(P& a){
        db tx = x, ty = y;
        x = a.x;  y = a.y;
        a.x = tx; a.y = ty;
    }
    bool operator < (const P a) const { return (x==a.x)?(y<a.y):(x<a.x); } 
    bool operator == (const P a) const { return (x==a.x)&&(y==a.y); }
}po[nmax];

int sign(db x) { return (x<-eps) ? -1 : x>eps; }
db disLP(P p1, P p2, P p){ return abs( (p1-p).times(p2-p) ) / (p1-p2).le(); }

bool intersection(P p1, P q1, P p2, P q2){
    if(max(p1.x,q1.x)+eps < min(p2.x,q2.x)) return false;
    if(max(p1.y,q1.y)+eps < min(p2.y,q2.y)) return false;
    if(max(p2.x,q2.x)+eps < min(p1.x,q1.x)) return false;
    if(max(p2.y,q2.y)+eps < min(p1.y,q1.y)) return false;
    int t1=sign( (p2-p1).times(q1-p1) )*sign( (q1-p1).times(q2-p1) ), 
    t2=sign( (p1-p2).times(q2-p2) )*sign( (q2-p2).times(q1-p2) );
    return (t1>=0) && (t2>=0);
}

db disSP(P p1, P p2, P p){
    if((p1-p2).dot(p-p2) < eps) return (p-p2).le();
    if((p2-p1).dot(p-p1) < eps) return (p-p1).le();
    return disLP(p1, p2, p);
}

db disSS(P p1, P q1, P p2, P q2){
    if( intersection(p1, q1, p2, q2) ) return 0;
    db a = disSP(p1,q1,p2);
    db b = disSP(p1,q1,q2);
    db c = disSP(p2,q2,p1);
    db d = disSP(p2,q2,q1);
    return min(min(a,b),min(c,d) );
}

int main(){
    //freopen("owo.in","r",stdin);
    int q;
    P p1, q1, p2, q2;
    cin >> q;
    while(q--){
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&q1.x,&q1.y,&p2.x,&p2.y,&q2.x,&q2.y);
        printf("%.10lf\n", disSS(p1, q1, p2, q2));
    }
    return 0;
}