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 <iomanip>
#include <cmath>
using namespace std;
#define EPS (1e-10)

static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

struct Point { double x, y; };//点
struct Segment { Point p1, p2; };//線
double dot(Point a, Point b) {//内積
    return a.x * b.x + a.y * b.y;
}
double cross(Point a, Point b) {//外積
    return a.x * b.y - a.y * b.x;
}
double norm(Point a) {
    return a.x * a.x + a.y * a.y;
}
double absv(Point a) {
    return sqrt(norm(a));
}
Point project(Segment s, Point p) {
    Point base, q;
    Point ans;
    base.x = s.p2.x - s.p1.x;
    base.y = s.p2.y - s.p1.y;
    q.x = p.x - s.p1.x;
    q.y = p.y - s.p1.y;
    double r = dot(q, base) / norm(base);
    ans.x = s.p1.x + base.x * r;
    ans.y = s.p1.y + base.y * r;
    return ans;
}
Point reflect(Segment s, Point p) {
    Point ans;
    ans.x = p.x + (project(s, p).x - p.x) * 2.0;
    ans.y = p.y + (project(s, p).y - p.y) * 2.0;
    return ans;
}
double getPointDistance(Point a, Point b) {
    Point ans;
    ans.x = a.x - b.x;
    ans.y = a.y - b.y;
    return absv(ans);
}
double getDistanceLP(Segment l, Point p) {
    Point tmp, tmp2;
    tmp.x = l.p2.x - l.p1.x;
    tmp.y = l.p2.y - l.p1.y;
    tmp2.x = p.x - l.p1.x;
    tmp2.y = p.y - l.p1.y;
    return abs(cross(tmp, tmp2) / absv(tmp));
}
double getDistanceSP(Segment s, Point p) {
    Point t1, t2, t3, t4;
    t1.x = s.p2.x - s.p1.x;
    t1.y = s.p2.y - s.p1.y;
    t2.x = p.x - s.p1.x;
    t2.y = p.y - s.p1.y;
    t3.x = s.p1.x - s.p2.x;
    t3.y = s.p1.y - s.p2.y;
    t4.x = p.x - s.p2.x;
    t4.y = p.y - s.p2.y;
    if (dot(t1, t2) < 0.0)return absv(t2);
    if (dot(t3, t4) < 0.0)return absv(t4);
    return getDistanceLP(s, p);
}
int ccw(Point p0,Point p1,Point p2){
    Point a,b;
    a.x=p1.x-p0.x;
    a.y=p1.y-p0.y;
    b.x=p2.x-p0.x;
    b.y=p2.y-p0.y;
    if(cross(a,b)>EPS)return COUNTER_CLOCKWISE;
    if(cross(a,b)<(-EPS))return CLOCKWISE;
    if(dot(a,b)<(-EPS))return ONLINE_BACK;
    if(norm(a)<norm(b))return ONLINE_FRONT;
    
    return ON_SEGMENT;
}
bool intersect(Point p1,Point p2,Point p3,Point p4){
    return(ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 && ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}
bool intersectS(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}
Point getCrossPoint(Segment s1,Segment s2){
    Point base,a,b,c;
    base.x=s2.p2.x-s2.p1.x;
    base.y=s2.p2.y-s2.p1.y;
    a.x=s1.p1.x-s2.p1.x;
    a.y=s1.p1.y-s2.p1.y;
    b.x=s1.p2.x-s2.p1.x;
    b.y=s1.p2.y-s2.p1.y;
    double d1=abs(cross(base,a));
    double d2=abs(cross(base,b));
    double t=d1/(d1+d2);
    c.x=s1.p1.x+(s1.p2.x-s1.p1.x)*t;
    c.y=s1.p1.y+(s1.p2.y-s1.p1.y)*t;
    return c;
}
double getDistance(Segment s1,Segment s2){
    if(intersectS(s1,s2))return 0.0;
    double a,b;
    a=min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2));
    b=min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2));
    return min(a,b);
}

int main(void) {
    Segment a,b;
    int n;cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a.p1.x >> a.p1.y >> a.p2.x >> a.p2.y;
        cin >> b.p1.x >> b.p1.y >> b.p2.x >> b.p2.y;
        cout << fixed << setprecision(10) << getDistance(a,b) << endl;
    }
    return 0;
}