#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
#include <valarray>
#include <queue>
#include <utility>
#include <functional>
#include <list>


using namespace std;

const double ESP = 1E-8;

struct Point
{
    //friends
    friend Point operator*(double c, const Point & p);
    friend ostream & operator<<(ostream & os, const Point & p);
    friend istream & operator>>(istream & is, Point & p);
    friend double cross(const Point & p1, const Point & p2);

  
    //members
    double x, y;

    Point() {};
    Point(double x, double y): x(x), y(y) {};

    Point operator-(const Point & p) const
    {
        return Point(x - p.x, y - p.y);
    }

    double operator*(const Point & p) const
    {
        return x*p.x + y*p.y;
    }

    Point operator*(double c) const
    {
        return Point(c*x, c*y);
    }

    Point operator+(const Point & p) const
    {
        return Point(x+p.x, y+p.y);
    }

    Point projection(const Point & p1, const Point & p2) const
    {
        Point a(*this-p1), b(p2-p1);
        return (a*b)/(b*b)*b+p1;
    }

    Point reflection(const Point & p1, const Point & p2) const
    {
        return this->projection(p1, p2)*2 - *this;
    }

};


struct Line
{
    Line() = default;
    Line(const Point & p1, const Point & p2): 
        direction(p1-p2), point_online(p1) {}; 
    Point direction, point_online;
};

struct Segment: public Line
{
    Segment() = default;
    Segment(const Point & p1, const Point & p2): 
        first_end(p1), second_end(p2), direction(p2-p1), 
        length(sqrt(direction*direction)), a(direction.y), 
        b(-direction.x), c(direction.x*p1.y-direction.y*p1.x)
        {/*norm(p2-p1);*/};

    Point first_end, second_end, direction;
    double length, a, b, c;
};


//function related with point
double norm(const Point & p);
bool check_clockwise(const Point & p0, const Point & p1, const Point & p2);
bool check_counter_clockwise(const Point & p0, const Point & p1, const Point & p2);
bool check_online_back(const Point & p0, const Point & p1, const Point & p2);
bool check_online_front(const Point & p0, const Point & p1, const Point & p2);
bool check_on_segment(const Point & p0, const Point & p1, const Point & p2);
// bool check_parallel(const Point & p0, const Point & p1, const Point & p2, const Point & p3);


//functions related with lines
bool check_parallel(const Line & l1, const Line & l2);
bool check_orthogonal(const Line & l1, const Line & l2);
bool check_intersection(const Segment & s1, const Segment & s2);
Point get_cross_point(const Segment & s1, const Segment & s2);



int main()
{
    Point p0, p1, p2, p3;

    int q;
    cin >> q;

    int result;

    for (int i = 0; i < q; i++)
    {
        cin >> p0 >> p1 >> p2 >> p3;

        cout << get_cross_point(Segment(p0, p1), Segment(p2, p3));
    }

}


//friends
Point operator*(double c, const Point & p)
{
    return p*c;
}

ostream & operator<<(ostream & os, const Point & p) 
{
    os << setprecision(8) << fixed << p.x << ' ' << p.y << endl;
    return os;
}

istream & operator>>(istream & is, Point & p)
{
    is >> p.x >> p.y;
    return is;
}

double cross(const Point & p1, const Point & p2)
{
    return p1.x*p2.y-p1.y*p2.x;
}

bool check_counter_clockwise(const Point & p0, const Point & p1, const Point & p2)
{
    return cross(p1-p0,p2-p0) > 0;
}

bool check_clockwise(const Point & p0, const Point & p1, const Point & p2)
{
    return cross(p1-p0,p2-p0) < 0;
}

double norm(const Point & p)
{
    return sqrt(p*p);
}

bool check_online_back(const Point & p0, const Point & p1, const Point & p2)
{
    Point a(p2-p0), b(p1-p0);
    double norm_a = norm(a), norm_b = norm(b);
    return fabs(a*b+norm_a*norm_b)<ESP && fabs(norm_a)>ESP;
}

bool check_online_front(const Point & p0, const Point & p1, const Point & p2)
{
    Point a(p2-p0), b(p1-p0);
    double norm_a = norm(a), norm_b = norm(b);
    return fabs(a*b-norm_a*norm_b)<ESP && norm_a>norm_b && fabs(norm_a-norm_b)>ESP;
}

bool check_on_segment(const Point & p0, const Point & p1, const Point & p2)
{
    Point a(p2-p0), b(p1-p0);
    double norm_a = norm(a), norm_b = norm(b);
    return fabs(a*b-norm_a*norm_b)<ESP && ((norm_a<norm_b && fabs(norm_a-norm_b)>ESP) || fabs(norm_a-norm_b)<ESP);
}

bool check_parallel(const Line & l1, const Line & l2)
{
    return cross(l1.direction, l2.direction)==0;
}

bool check_orthogonal(const Line & l1, const Line & l2)
{
    return l1.direction*l2.direction==0;
}

bool check_on_segment(const  Segment & s, const Point & p)
{
    return cross(p-s.first_end, p-s.second_end)==0 && max(norm(p-s.first_end), norm(p-s.second_end))-s.length <= ESP;
}

bool check_intersection(const Segment & s1, const Segment & s2)
{
    bool mutually_different_side = 
        check_clockwise(s1.first_end, s1.second_end, s2.first_end) ==
        check_counter_clockwise(s1.first_end, s1.second_end, s2.second_end) &&
        check_clockwise(s2.first_end, s2.second_end, s1.first_end) ==
        check_counter_clockwise(s2.first_end, s2.second_end, s1.second_end) &&
        cross(s1.direction, s2.direction)!=0; //not parallel
        

    bool on_segment = 
        check_on_segment(s1, s2                                                                                                                                                     .first_end) ||
        check_on_segment(s1, s2.second_end) ||
        check_on_segment(s2, s1.first_end) ||
        check_on_segment(s2, s1.second_end);

    return mutually_different_side || on_segment;

}


Point get_cross_point(const Segment & s1, const Segment & s2)
{
    // if (!check_intersection(s1,s2))
    //     return;

    double D = s1.a*s2.b - s2.a*s1.b, D1 = -(s1.c*s2.b-s1.b*s2.c), D2 = -(s1.a*s2.c-s2.a*s1.c);

    return Point(D1/D, D2/D);
}


Measured memory_bytes: 3292