#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

const double eps = 1e-9;
inline bool equals(double a, double b) { return fabs(a - b) < eps ;}

class Point {
public:
    double x, y;

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

    Point operator + (Point p) { return Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(a * x, a * y); }
    Point operator / (double a) { return Point(x / a, y / a); }

    double abs() { return sqrt(norm()); }
    double norm() { return x * x + y * y; }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
    }
};
typedef Point Vector;

struct Segment { Point p1, p2; };

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

// return abs of closs product
double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

Point cross_point(Segment s1, Segment s2) {
    Vector base = s2.p2 - s2.p1;
    double d1 = abs(cross(base, s1.p1 - s2.p1));
    double d2 = abs(cross(base, s1.p2 - s2.p1));
    double t = d1 / (d1 + d2);
    return s1.p1 + (s1.p2 - s1.p1) * t;
}

int main(void) {
    int q;
    cin >> q;
    while (q--) {
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        Segment s1 = {Point(x0, y0), Point(x1, y1)};
        Segment s2 = {Point(x2, y2), Point(x3, y3)};
        Point c = cross_point(s1, s2);
        printf("%.10f %.10f\n", c.x, c.y);
    }
    return 0;
}