require 'matrix'
q = gets.to_i

class Segment
  attr_accessor :p1, :p2
  def initialize(p1, p2)
    @p1 = p1
    @p2 = p2
  end
end

def get_distance_sp(s, p)
  return (s.p1 - p).norm if (s.p2 - s.p1).inner_product(p - s.p1)
  return (s.p2 - p).norm if (s.p1 - s.p2).inner_product(p - s.p2)
  return (s.p2 - s.p1).cross_product(p - s.p1) / (s.p2 - s.p1).norm
end

q.times do
  x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map &:to_i
  p0 = Vector[ x0, y0, 0 ]
  p1 = Vector[ x1, y1, 0 ]
  p2 = Vector[ x2, y2, 0 ]
  p3 = Vector[ x3, y3, 0 ]
  s1 = Segment.new(p0, p1)
  s2 = Segment.new(p2, p3)
  return [ get_distance_sp(s1, s2.p1), get_distance_sp(s1, s2.p2), get_distance_sp(s2, s1.p1), get_distance_sp(s2, s1.p2) ].min
end