#include <iostream>
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <tuple>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

double eps = 1e-8;

struct point {
    double x, y;
    point operator+(const point &p) {
        return {x + p.x, y + p.y};
    }
    point operator-(const point &p) {
        return {x - p.x, y - p.y};
    }
};

struct line {
    // ax + by + c = 0
    double a, b, c;
};

struct circle {
    point p;
    double r;
};

double distance(point A, point B, int deg) {
    point C = B - A;
    return pow(C.x*C.x + C.y*C.y, 0.5 * deg);
}

line line_2points(point P, point Q) {
    return {P.y - Q.y, Q.x - P.x, P.x*Q.y - P.y*Q.x};
}

point lines_intersection(line l, line m) {
    if (abs(l.a*m.b - l.b*m.a) < eps) {
        assert(-1);
    }
    return {- (l.b*m.c - l.c*m.b) / (l.b*m.a - l.a*m.b),
            - (l.a*m.c - l.c*m.a) / (l.a*m.b - l.b*m.a)};
}

bool line_same(line l, line m) {
    if (l.c * m.c == 0) {
        if (l.c == m.c) {
            if (l.b * m.b == 0) {
                if (l.b == m.b) return 1;
                else return 0;
            }
            else return l.a / l.b == m.a / m.b; 
        }
        else return 0;
    }
    else return l.a / l.c == m.a / m.c && l.b / l.c == m.b / m.c;
}

bool on_line(point P, point Q, point R) {
    if (P.x > Q.x) swap(P, Q);
    if (P.y > Q.y) swap(P.y, Q.y);
    return (P.x <= R.x && R.x <= Q.x && P.y <= R.y && R.y <= Q.y);
}

vector<point> circles_intersection(circle A, circle B) {
    vector<point> ret;
    point X = A.p;
    B.p = B.p - A.p;
    A.p = {0, 0};

    if (distance(A.p, B.p, 2) - pow(A.r + B.r, 2) > eps) return ret;

    double K = (B.p.x*B.p.x + B.p.y*B.p.y + A.r*A.r - B.r*B.r) / 2;
    double SQ = (B.p.x*B.p.x + B.p.y*B.p.y)*A.r*A.r - K * K;
    double DS = distance(A.p, B.p, 2);
    //cerr << K _ SQ _ DS << endl;
    if (abs(SQ) < eps) {
        ret.push_back({K*B.p.x / DS + X.x, K*B.p.y / DS + X.y});
        return ret;
    }
    ret.push_back({(K*B.p.x + B.p.y*sqrt(SQ)) / DS + X.x,
                   (K*B.p.y - B.p.x*sqrt(SQ)) / DS + X.y});
    ret.push_back({(K*B.p.x - B.p.y*sqrt(SQ)) / DS + X.x,
                   (K*B.p.y + B.p.x*sqrt(SQ)) / DS + X.y});
    return ret;
}
 
int main() {
    cout << fixed << setprecision(10);
    int q;
    cin >> q;
    while (q--) {
        point p[4];
        for (int i = 0; i < 4; i++) {
            cin >> p[i].x >> p[i].y;
        }
        line s0 = line_2points(p[0], p[1]);
        line s1 = line_2points(p[2], p[3]);
        /*
        if (abs(s0.a*s1.b - s0.b*s1.a) < eps) {
            if (p[0].x > p[1].x) swap(p[0], p[1]);
            if (p[0].y > p[1].y) swap(p[0].y, p[1].y);
            if (p[2].x > p[3].x) swap(p[2], p[3]);
            if (p[2].y > p[3].y) swap(p[2].y, p[3].y);
            if (line_same(s0, s1)) {
                cout << (p[2].x <= p[1].x && p[0].x <= p[3].x
                      && p[2].y <= p[1].y && p[0].y <= p[3].y) << endl;

            }
            else cout << 0 << endl;
            continue;
        }*/

        point r = lines_intersection(s0, s1);
        //cerr << r.x _ r.y << endl;
        if (r.x == -0) r.x = 0;
        if (r.y == -0) r.y = 0;
        cout << r.x _ r.y << endl;
    }
}


Measured memory_bytes: 3296