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 lb long double
#define eps 1e-10
using namespace std;
struct Po{lb x,y;}p0,p1,q0,q1;
int t;
void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);}
Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
Po operator +(Po x,Po y){return (Po){x.x+y.x,x.y+y.y};}
lb operator *(Po x,Po y){return x.x*y.y-x.y*y.x;}
lb operator ^(Po x,Po y){return x.x*y.x+x.y*y.y;}
bool dotinline(Po x,Po y,Po z){
	if (x.x>y.x) swap(x,y);
	if (z.x<x.x-eps||z.x>y.x+eps) return 0;
	if (x.y>y.y) swap(x,y);
	if (z.y<x.y-eps||z.y>y.y+eps) return 0;
	return 1;
}
bool getcross(Po p0,Po p1,Po q0,Po q1){
	Po np=p1-p0,nq=q1-q0;
	lb a1=np*(q0-p0),a2=np*(q1-p0),a3=nq*(p0-q0),a4=nq*(p1-q0);
	if (a1*a2<-eps&&a3*a4<-eps) return 1;
	if (fabs(a1)<eps&&dotinline(p0,p1,q0)) return 1;
	if (fabs(a2)<eps&&dotinline(p0,p1,q1)) return 1;
	if (fabs(a3)<eps&&dotinline(q0,q1,p0)) return 1;
	if (fabs(a4)<eps&&dotinline(q0,q1,p1)) return 1;
	return 0;
}
lb dis(Po x){return sqrtl(x.x*x.x+x.y*x.y);}
lb getd(Po x,Po y,Po z){
	if (((y-x)^(z-x))<eps)return dis(x-z);
	if (((x-y)^(z-y))<eps)return dis(y-z);
	return fabs((y-x)*(z-x))/dis(x-y);
}
int main(){
	scanf("%d",&t);
	while (t--){
		get(p0);get(p1);get(q0);get(q1);
		if (getcross(p0,p1,q0,q1)) printf("0\n");
		else printf("%.10Lf\n",min(min(getd(p0,p1,q0),getd(p0,p1,q1)),min(getd(q0,q1,p0),getd(q0,q1,p1))));
	}
	return 0;
}