using System;
using System.Text;

namespace CGL_2_D_Distance
{
	class Program
	{
		static void Main ( string[] args )
		{
			int inputCount = int.Parse (Console.ReadLine ());
			StringBuilder output = new StringBuilder (inputCount * 15);

			for (int lp = 0; lp < inputCount; lp++)
			{
				int[] inputNum = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);

				Vector2 point1 = new Vector2 (inputNum[0], inputNum[1]);
				Vector2 point2 = new Vector2 (inputNum[2], inputNum[3]);
				Vector2 point3 = new Vector2 (inputNum[4], inputNum[5]);
				Vector2 point4 = new Vector2 (inputNum[6], inputNum[7]);

				decimal result = Vector2.Distance (point1, point2, point3, point4);

				output.Append (result);
				output.AppendLine ();
			}

			Console.Write (output);
		}
	}

	class Vector2
	{
		public Vector2 ( decimal x, decimal y )
		{
			this.X = x;
			this.Y = y;
		}

		public decimal X { private set; get; }
		public decimal Y { private set; get; }

		public static Vector2 operator + ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X + ob2.X, ob1.Y + ob2.Y);
		}
		public static Vector2 operator - ( Vector2 ob1, Vector2 ob2 )
		{
			return new Vector2 (ob1.X - ob2.X, ob1.Y - ob2.Y);
		}
		public static Vector2 operator * ( Vector2 ob, decimal scalar )
		{
			return new Vector2 (ob.X * scalar, ob.Y * scalar);
		}

		public decimal Length ()
		{
			return X * X + Y * Y;
		}

		public static decimal DotProduct ( Vector2 line1, Vector2 line2 )
		{
			return line1.X * line2.X + line1.Y * line2.Y;
		}
		public static decimal CrossProduct ( Vector2 line1, Vector2 line2 )
		{
			return line1.X * line2.Y - line1.Y * line2.X;
		}
		public static decimal Sqrt ( decimal number )
		{
			return new decimal (Math.Sqrt (decimal.ToDouble (number)));
		}

		public static decimal Distance ( Vector2 point1, Vector2 point2 )
		{
			return Sqrt ((point1 - point2).Length ());
		}

		public static decimal DistanceLP ( Vector2 linePoint1, Vector2 linePoint2, Vector2 point )
		{
			return Math.Abs (
				CrossProduct (linePoint2 - linePoint1, point - linePoint1) / Sqrt ((linePoint2 - linePoint1).Length ())
				);
		}

		public static decimal DistanceSP ( Vector2 linePoint1, Vector2 linePoint2, Vector2 point )
		{
			if (DotProduct (linePoint2 - linePoint1, point - linePoint1) < 0m)
				return Sqrt ((point - linePoint1).Length ());
			if (DotProduct (linePoint1 - linePoint2, point - linePoint2) < 0m)
				return Sqrt ((point - linePoint2).Length ());

			return DistanceLP (linePoint1, linePoint2, point);
		}

		public static decimal Distance ( Vector2 line1Point1, Vector2 line1Point2, Vector2 line2Point1, Vector2 line2Point2 )
		{
			if (Intersection (line1Point1, line1Point2, line2Point1, line2Point2))
			{
				return 0m;
			}

			return Math.Min (
				Math.Min (DistanceSP (line1Point1, line1Point2, line2Point1),
				DistanceSP (line1Point1, line1Point2, line2Point2)),

				Math.Min (DistanceSP (line2Point1, line2Point2, line1Point1),
				DistanceSP (line2Point1, line2Point2, line1Point2))
			);
		}

		public const int Counter_Clockwise = 1;
		public const int Clockwise = -1;
		public const int OnlineBack = 2;
		public const int OnlineFront = -2;
		public const int OnSegment = 0;

		public static int PointState ( Vector2 point1, Vector2 point2, Vector2 point3 )
		{
			Vector2 line1 = point2 - point1;
			Vector2 line2 = point3 - point1;

			decimal crossProduct = CrossProduct (line1, line2);

			if (crossProduct > 0m)
			{
				return Counter_Clockwise;
			}
			else if (crossProduct < 0m)
			{
				return Clockwise;
			}
			else if (DotProduct (line1, line2) < 0m)
			{
				return OnlineBack;
			}
			else if (line1.Length () < line2.Length ())
			{
				return OnlineFront;
			}

			return OnSegment;
		}

		public static bool Intersection ( Vector2 line1Point1, Vector2 line1Point2, Vector2 line2Point1, Vector2 line2Point2 )
		{
			Vector2 p1 = line1Point1;
			Vector2 p2 = line1Point2;
			Vector2 p3 = line2Point1;
			Vector2 p4 = line2Point2;

			return (PointState (p1, p2, p3) * PointState (p1, p2, p4) <= 0 &&
				PointState (p3, p4, p1) * PointState (p3, p4, p2) <= 0);
		}
	}
}

Measured memory_bytes: 9720