using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
//using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int NQ = Reader.Int();

        for (int q = 0; q < NQ; q++)
        {
            var a = new Point(Reader.Int(), Reader.Int());
            var b = new Point(Reader.Int(), Reader.Int());
            var c = new Point(Reader.Int(), Reader.Int());
            var d = new Point(Reader.Int(), Reader.Int());
            var seg1 = new Segment(a, b);
            var seg2 = new Segment(c, d);
            Console.WriteLine(Distance(seg1, seg2));
        }
        Console.ReadLine();
    }

    public Point Projection(Point p, Segment seg)
    {
        Point v = seg.B - seg.A;
        return seg.A + v * (v.Dot(p - seg.A) / v.Dot(v));
    }

    public bool OnSegment(Point p, Segment s)
    {
        return (s.A - p).Det(s.B - p) == 0 && (s.A - p).Dot(s.B - p) <= 0;
    }
    public bool OnSegment(Point p, Point seg1, Point seg2)
    {
        return (seg1 - p).Det(seg2 - p) == 0 && (seg1 - p).Dot(seg2 - p) <= 0;
    }

    public double Distance(Point p, Segment seg)
    {
        var q = Projection(p, seg);
        if (OnSegment(q, seg)) return p.Distance(q);
        return Math.Min(p.Distance(seg.A), p.Distance(seg.B));
    }

    public double Distance(Segment seg1, Segment seg2)
    {
        if (SegmentIntersect(seg1, seg2)) return 0;
        return Math.Min(Math.Min(Distance(seg1.A, seg2), Distance(seg1.B, seg2)),
                        Math.Min(Distance(seg2.A, seg1), Distance(seg2.B, seg1)));
    }

    bool SegmentIntersect(Segment seg1, Segment seg2)
    {
        var c1 = (seg1.B - seg1.A).Det(seg2.A - seg1.A);
        if (c1 == 0 && (seg1.A - seg2.A).Dot(seg1.B - seg2.A) <= 0) return true;
        var c2 = (seg1.B - seg1.A).Det(seg2.B - seg1.A);
        if (c2 == 0 && (seg1.A - seg2.B).Dot(seg1.B - seg2.B) <= 0) return true;
        var c3 = (seg2.B - seg2.A).Det(seg1.A - seg2.A);
        if (c3 == 0 && (seg2.A - seg1.A).Dot(seg2.B - seg1.A) <= 0) return true;
        var c4 = (seg2.B - seg2.A).Det(seg1.B - seg2.A);
        if (c4 == 0 && (seg2.A - seg1.B).Dot(seg2.B - seg1.B) <= 0) return true;
        return c1 * c2 < 0 && c3 * c4 < 0;
    }

    
    public class Segment
    {
        public Point A, B;
        public Segment(Point a, Point b) { A = a; B = b; }
    }

    public struct Point : IEquatable<Point>, IComparable<Point>
    {
        public static readonly double Eps = 1e-10;
        public double X, Y;

        public Point(double x, double y) { X = x; Y = y; }

        public static Point operator +(Point a, Point b)
        {
            return new Point(Add(a.X, b.X), Add(a.Y, b.Y));
        }
        public static Point operator -(Point a, Point b)
        {
            return new Point(Add(a.X, -b.X), Add(a.Y, -b.Y));
        }
        public static Point operator *(Point p, double d)
        {
            return new Point(p.X * d, p.Y * d);
        }
        public double Distance(Point b) { return Math.Sqrt((b - this).Dot(b - this)); }
        public double Dot(Point b) { return Add(X * b.X, Y * b.Y); }
        public double Det(Point b) { return Add(X * b.Y, -Y * b.X); }
        public bool Equals(Point b) { return X == b.X && Y == b.Y; }
        public int CompareTo(Point b) { return X != b.X ? Math.Sign(X - b.X) : Math.Sign(Y - b.Y); }
        public override int GetHashCode() { return (int)(X * 100000 + Y); }
        public override string ToString() { return X + ", " + Y; }

        private static double Add(double a, double b)
        {
            if (Math.Abs(a + b) < Eps * (Math.Abs(a) + Math.Abs(b))) return 0;
            return a + b;
        }
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    private static TextReader reader = Console.In;
    private static readonly char[] separator = { ' ' };
    private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    private static string[] A = new string[0];
    private static int i;
    private static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Next()).ToArray(); }
    public static string Line() { return reader.ReadLine().Trim(); }
    private static string[] Split(string s) { return s.Split(separator, op); }
    private static string Next() { CheckNext(); return A[i++]; }
    private static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 9580