using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly double EPS = 1E-10;

        static void Main(string[] args)
        {
            int q = int.Parse(Console.ReadLine());

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < q; i++)
            {
                double[] input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
                Pt a = new Pt(input[0], input[1]);
                Pt b = new Pt(input[2], input[3]);
                Pt c = new Pt(input[4], input[5]);
                Pt d = new Pt(input[6], input[7]);

                Seg s1 = new Seg(a, b);
                Seg s2 = new Seg(c, d);

                sb.AppendLine(GetCrossPoint(s1, s2).ToString());
            }
            Console.Write(sb);
        }

        static Pt GetCrossPoint(Seg s1,Seg s2)
        {
            Pt b = s2.p2 - s2.p1;
            double d1 = Math.Abs(b.Cross(s1.p1 - s2.p1));
            double d2 = Math.Abs(b.Cross(s1.p2 - s2.p1));
            double t = d1 / (d1 + d2);
            return s1.p1 + (s1.p2 - s1.p1) * t;
        }

        static bool IsIntersect(Pt p1, Pt p2, Pt p3, Pt p4)
        {
            return CCW(p1, p2, p3) * CCW(p1, p2, p4) <= 0 &&
                   CCW(p3, p4, p1) * CCW(p3, p4, p2) <= 0;
        }

        static int CCW(Pt p0, Pt p1, Pt p2)
        {
            Pt a = p1 - p0, b = p2 - p0;

            if (a.Cross(b) > EPS) return 1;
            if (a.Cross(b) < -EPS) return -1;
            if (a.Dot(b) < -EPS) return 2;
            if (a.Norm < b.Norm) return -2;
            return 0;
        }
    }

    class Pt : IComparable<Pt>
    {
        static readonly double EPS = 1E-10;

        internal double x, y;

        public Pt(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public double Abs { get { return Math.Sqrt(Norm); } }
        public double Norm { get { return x * x + y * y; } }

        public double Dot(Pt p) { return x * p.x + y * p.y; }
        public double Cross(Pt p) { return x * p.y - y * p.x; }

        public static Pt operator +(Pt a, Pt b) { return new Pt(a.x + b.x, a.y + b.y); }
        public static Pt operator -(Pt a, Pt b) { return new Pt(a.x - b.x, a.y - b.y); }
        public static Pt operator *(Pt p, double d) { return new Pt(p.x * d, p.y * d); }
        public static Pt operator /(Pt p, double d) { return new Pt(p.x / d, p.y / d); }
        public static bool operator <(Pt a, Pt b) { return Math.Abs(a.x - b.x) > EPS ? a.x < b.x : a.y < b.y; }
        public static bool operator >(Pt a, Pt b) { return Math.Abs(a.x - b.x) > EPS ? a.x > b.x : a.y > b.y; }
        public static bool operator ==(Pt a, Pt b) { return Math.Abs(a.x - b.x) < EPS && Math.Abs(a.y - b.y) < EPS; }
        public static bool operator !=(Pt a, Pt b) { return Math.Abs(a.x - b.x) >= EPS || Math.Abs(a.y - b.y) >= EPS; }

        public int CompareTo(Pt other)
        {
            return x != other.x ? (int)(x - other.x) : (int)(y - other.y);
        }

        public override bool Equals(object obj)
        {
            Pt other = (Pt)obj;
            return Math.Abs(x - other.x) < EPS && Math.Abs(y - other.y) < EPS;
        }

        public override int GetHashCode()
        {
            return x.GetHashCode() ^ y.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0:f10} {1:f10}", x, y);
        }
    }

    class Seg
    {
        internal Pt p1, p2;

        public Seg(Pt a, Pt b)
        {
            p1 = a;
            p2 = b;
        }
    }
}

Measured memory_bytes: 9712