def is_intersection(x0, y0, x1, y1, x2, y2, x3, y3)
  if x0 < x1 && ((x2 < x0 && x3 < x0) || (x1 < x2 && x1 < x3))
    return false
  elsif x1 <= x0 && ((x2 < x1 && x3 < x1) || (x0 < x2 && x0 < x3))
    return false
  elsif y0 < y1 && ((y2 < y0 && y3 < y0) || (y1 < y2 && y1 < y3))
    return false
  elsif y1 <= y0 && ((y2 < y1 && y3 < y1) || (y0 < y2 && y0 < y3))
    return false
  else
    t0 = (x0-x1) * (y2-y0) + (y0-y1) * (x0-x2)
    t1 = (x0-x1) * (y3-y0) + (y0-y1) * (x0-x3)
    t2 = (x2-x3) * (y0-y2) + (y2-y3) * (x2-x0)
    t3 = (x2-x3) * (y1-y2) + (y2-y3) * (x2-x1)
    if t0 * t1 <= 0 && t2 * t3 <= 0
      return true
    else
      return true
    end
  end
end

def distance(x0, y0, x1, y1, qx, qy)
  v0 = [x1 - x0, y1 - y0]
  v1 = [qx - x0, qy - y0]
  inner_product = v0[0]*v1[0]+v0[1]*v1[1]
  if inner_product <= 0
    return Math.sqrt(v1[0]*v1[0]+v1[1]*v1[1])
  elsif inner_product < v0[0]*v0[0]+v0[1]*v0[1]
    d22 = inner_product * inner_product / (v0[0]*v0[0]+v0[1]*v0[1])
    return Math.sqrt(v1[0]*v1[0]+v1[1]*v1[1] - d22)
  else
    v1 = [qx - x1, qy - y1]
    return Math.sqrt(v1[0]*v1[0]+v1[1]*v1[1])
  end
end

q = gets.to_i
q.times{
  x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_i)
  if is_intersection(x0, y0, x1, y1, x2, y2, x3, y3)
    puts 0.0
  else
    puts [distance(x0, y0, x1, y1, x2, y2), distance(x0, y0, x1, y1, x3, y3), distance(x2, y2, x3, y3, x0, y0), distance(x2, y2, x3, y3, x1, y1)].min
  end
}