import scala.io.StdIn._

import Math._
object Main extends App {
  val eps0 = 1e-12

  val q = readLine.toInt
  for (i <- 0 until q) {
    val Seq(xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3) = readLine.split(' ').map(_.toDouble).toList
    val sx1 = xp1 - xp0
    val sy1 = yp1 - yp0
    val sx2 = xp3 - xp2
    val sy2 = yp3 - yp2
    val vx1 = xp2 - xp0
    val vy1 = yp2 - yp0

    val det = -sx1*sy2 + sy1*sx2

    val t = (-sy2 * vx1 + sx2 * vy1) / det
    val u = (-sy1 * vx1 + sx1 * vy1) / det

    println("%.10f %.10f".format(sx1 * t + xp0, sy1 * t + yp0))
  }
}
