let to_array s = Str.split (Str.regexp_string " ") s
                 |> List.map float_of_string
                 |> Array.of_list;;

let () =
  let n = read_int () in
  let rec read = function
    0 -> ()
    | i ->
       let l = read_line () |> to_array in
       let (x1,y1,x2,y2,x3,y3,x4,y4) = (l.(0),l.(1),l.(2),l.(3),l.(4),l.(5),l.(6),l.(7)) in
       let a = y2 -. y1 and b = x1 -. x2 and e = x1*.y2 -. x2 *. y1 and
           c = y4 -. y3 and d = x3 -. x4 and f = x3*.y4 -. x4 *. y3 in
       let adbc = a *. d -. b *. c and s = e *. d -. b *. f and t = a *. f -. e *. c in
       let x = s/.adbc and y = t/.adbc and
           f z = if z = -0.0 then 0.0 else z in
       Printf.printf "%.10f %.10f\n" (f x) (f y);
       read (i-1)
  in read n;;