object Main extends App {
  import scala.io.StdIn._
  for (_ ← 0 until readInt()) {
    val Array(x0, y0, x1, y1, x2, y2, x3, y3) = readLine.trim.split(' ').map(_.toInt)
    val a = Line(Coordinate(x0, y0), Coordinate(x1, y1))
    val b = Line(Coordinate(x2, y2), Coordinate(x3, y3))
    println(f"${a.distance(b)}%.10f")
  }
}

case class Coordinate(x: Double, y: Double) {
  def distance(that: Coordinate): Double = (this - that).length
  def -(that: Coordinate): Vector = Vector(x - that.x, y - that.y)
}
case class Vector(x: Double, y: Double) {
  def length: Double = math.sqrt(x * x + y * y)
  def dot(that: Vector): Double = x * that.x + y * that.y
  def cross(that: Vector): Double = x * that.y - y * that.x
  def sin(that: Vector): Double = cross(that) / length / that.length
  def cos(that: Vector): Double = dot(that) / length / that.length
}
case class Line(a: Coordinate, b: Coordinate) {
  def distance(that: Line): Double = {
    if ((a - b).sin(that.a - b) * (a - b).sin(that.b - b) < 0 && (that.a - that.b).sin(a - that.b) * (that.a - that.b).sin(b - that.b) < 0) {
      0.0
    }else {
      List(distance(that.a), distance(that.b), that.distance(a), that.distance(b)).min
    }
  }
  def distance(that: Coordinate): Double = {
    if ((a - b).cos(that - b) >= 0 && (b - a).cos(that - a) >= 0) a.distance(that) * (b - a).sin(that - a).abs
    else List(a.distance(that), b.distance(that)).min
  }
}
