macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::ops::{Add, Div, Mul, Neg, Sub};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Complex<T> {
    pub re: T,
    pub im: T,
}
impl<T> Complex<T> {
    #[inline]
    pub fn new(re: T, im: T) -> Complex<T> {
        Complex { re: re, im: im }
    }
}
impl<T: Neg<Output = T>> Complex<T> {
    #[inline]
    pub fn conjugate(self) -> Complex<T> {
        Self::new(self.re, -self.im)
    }
}
impl<T: Add<Output = T> + Mul<Output = T>> Complex<T> {
    #[inline]
    pub fn dot(self, other: Self) -> T {
        self.re * other.re + self.im * other.im
    }
}
impl<T: Sub<Output = T> + Mul<Output = T>> Complex<T> {
    #[inline]
    pub fn cross(self, other: Self) -> T {
        self.re * other.im - self.im * other.re
    }
}
impl Complex<f64> {
    #[inline]
    pub fn from_polar(r: f64, theta: f64) -> Self {
        Complex::new(r * theta.cos(), r * theta.sin())
    }
    #[inline]
    pub fn abs(self) -> f64 {
        self.re.hypot(self.im)
    }
    #[inline]
    pub fn unit(self) -> Self {
        self / self.abs()
    }
    #[inline]
    pub fn angle(self) -> f64 {
        self.im.atan2(self.re)
    }
}
impl<T: Add<Output = T>> Add for Complex<T> {
    type Output = Self;
    fn add(self, other: Self) -> Self::Output {
        Self::new(self.re + other.re, self.im + other.im)
    }
}
impl<T: Copy + Add<Output = T>> Add<T> for Complex<T> {
    type Output = Self;
    fn add(self, other: T) -> Self::Output {
        Self::new(self.re + other, self.im + other)
    }
}
impl<T: Sub<Output = T>> Sub for Complex<T> {
    type Output = Self;
    fn sub(self, other: Self) -> Self::Output {
        Self::new(self.re - other.re, self.im - other.im)
    }
}
impl<T: Copy + Sub<Output = T>> Sub<T> for Complex<T> {
    type Output = Self;
    fn sub(self, other: T) -> Self::Output {
        Self::new(self.re - other, self.im - other)
    }
}
impl<T: Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T>> Mul for Complex<T> {
    type Output = Self;
    fn mul(self, other: Self) -> Self::Output {
        Self::new(
            self.re * other.re - self.im * other.im,
            self.re * other.im + self.im * other.re,
        )
    }
}
impl<T: Copy + Mul<Output = T>> Mul<T> for Complex<T> {
    type Output = Self;
    fn mul(self, other: T) -> Self::Output {
        Self::new(self.re * other, self.im * other)
    }
}
impl<T: Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>> Div
    for Complex<T>
{
    type Output = Self;
    fn div(self, other: Self) -> Self::Output {
        let d = other.re * other.re + other.im * other.im;
        Self::new(
            (self.re * other.re + self.im * other.im) / d,
            (self.im * other.re - self.re * other.im) / d,
        )
    }
}
impl<T: Copy + Div<Output = T>> Div<T> for Complex<T> {
    type Output = Self;
    fn div(self, other: T) -> Self::Output {
        Self::new(self.re / other, self.im / other)
    }
}
impl<T: Neg<Output = T>> Neg for Complex<T> {
    type Output = Self;
    fn neg(self) -> Self::Output {
        Self::new(-self.re, -self.im)
    }
}
pub type Point = Complex<f64>;
#[derive(Clone, Debug, PartialEq)]
pub struct LineSegment {
    p1: Point,
    p2: Point,
}
impl LineSegment {
    pub fn new(p1: Point, p2: Point) -> Self {
        LineSegment { p1: p1, p2: p2 }
    }
    pub fn dir(&self) -> Point {
        self.p2 - self.p1
    }
    pub fn ccw(&self, p: Point) -> CCW {
        ccw(self.p1, self.p2, p)
    }
    pub fn projection(&self, p: Point) -> Point {
        let e = self.dir().unit();
        self.p1 + e * (p - self.p1).dot(e)
    }
    pub fn reflection(&self, p: Point) -> Point {
        p + (self.projection(p) - p) * 2.0
    }
    pub fn is_parallel(&self, other: &Self) -> bool {
        Real(self.dir().cross(other.dir())) == Real(0.)
    }
    pub fn is_orthogonal(&self, other: &Self) -> bool {
        Real(self.dir().dot(other.dir())) == Real(0.)
    }
    pub fn intersect(&self, other: &Self) -> bool {
        self.ccw(other.p1) as i8 * self.ccw(other.p2) as i8 <= 0
            && other.ccw(self.p1) as i8 * other.ccw(self.p2) as i8 <= 0
    }
    pub fn intersect_point(&self, p: Point) -> bool {
        self.ccw(p) == CCW::OnSegment
    }
    pub fn cross_point(&self, other: &Self) -> Option<Point> {
        if self.intersect(other) {
            let a = self.dir().cross(other.dir());
            let b = self.dir().cross(self.p2 - other.p1);
            if Real(a.abs()) == Real(0.) && Real(b.abs()) == Real(0.) {
                Some(other.p1)
            } else {
                Some(other.p1 + (other.dir() * b / a))
            }
        } else {
            None
        }
    }
    pub fn distance_point(&self, p: Point) -> f64 {
        let r = self.projection(p);
        if self.intersect_point(r) {
            (r - p).abs()
        } else {
            std::cmp::min(TotalOrd((self.p1 - p).abs()), TotalOrd((self.p2 - p).abs())).0
        }
    }
    pub fn distance(&self, other: &Self) -> f64 {
        use std::cmp::min;
        if self.intersect(other) {
            0.
        } else {
            min(
                min(
                    TotalOrd(self.distance_point(other.p1)),
                    TotalOrd(self.distance_point(other.p2)),
                ),
                min(
                    TotalOrd(other.distance_point(self.p1)),
                    TotalOrd(other.distance_point(self.p2)),
                ),
            )
            .0
        }
    }
}

pub const EPS: f64 = 1e-8;
#[derive(Clone, Debug)]
pub struct Real(pub f64);
impl PartialEq for Real {
    fn eq(&self, other: &Real) -> bool {
        (self.0 - other.0).abs() < EPS
    }
}
impl PartialOrd for Real {
    fn partial_cmp(&self, other: &Real) -> Option<std::cmp::Ordering> {
        if self == other {
            Some(std::cmp::Ordering::Equal)
        } else {
            self.0.partial_cmp(&other.0)
        }
    }
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum CCW {
    #[doc = " a--b--c"]
    OnlineFront = -2,
    #[doc = " a--b-vc"]
    Clockwise = -1,
    #[doc = " a--c--b"]
    OnSegment = 0,
    #[doc = " a--b-^c"]
    CounterClockwise = 1,
    #[doc = " c--a--b"]
    OnlineBack = 2,
}
pub fn ccw(a: Point, b: Point, c: Point) -> CCW {
    let x = b - a;
    let y = c - a;
    if Real(x.cross(y)) > Real(0.) {
        CCW::CounterClockwise
    } else if Real(x.cross(y)) < Real(0.) {
        CCW::Clockwise
    } else if Real(x.dot(y)) < Real(0.) {
        CCW::OnlineBack
    } else if Real(x.abs()) < Real(y.abs()) {
        CCW::OnlineFront
    } else {
        CCW::OnSegment
    }
}
#[derive(PartialEq, PartialOrd)]
pub struct TotalOrd<T>(pub T);
impl<T: PartialEq> Eq for TotalOrd<T> {}
impl<T: PartialOrd> Ord for TotalOrd<T> {
    fn cmp(&self, other: &TotalOrd<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
fn main() {
    input! { q, qs: [[(f64, f64); 4]; q] };
    for ps in &qs {
        let l1 = LineSegment::new(Point::new(ps[0].0, ps[0].1), Point::new(ps[1].0, ps[1].1));
        let l2 = LineSegment::new(Point::new(ps[2].0, ps[2].1), Point::new(ps[3].0, ps[3].1));
        let x = l1.distance(&l2);
        println!("{}", x);
    }
}



Measured memory_bytes: 5180