q = gets.to_i
q.times{
  x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f)
  a0 = (y1 - y0) / (x1 - x0)
  b0 = y0 - a0 * x0
  a1 = (y3 - y2) / (x3 - x2)
  b1 = y2 - a1 * x2
  if x0 == x1
    xp = x0
    yp = a1 * xp + b1
  elsif x2 == x3
    xp = x2
    yp = a0 * xp + b0
  else
    xp = (b0 - b1) / (a1 - a0)
    yp = a0 * xp + b0
  end
  puts "%.12f %.12f" % [xp, yp]
}