#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1, i##_end_ = (n); i <= i##_end_; ++i)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;


const double eps = 1e-10;
int sgn(double x) {
    if(fabs(x) < eps) return 0;
    return x < 0 ? -1 : 1;
}
struct Point {
    double x, y;
    Point(double xp=0, double yp=0): x(xp), y(yp) { }
    Point operator + (const Point& rhs) const { return Point(x+rhs.x, y+rhs.y); }
    Point operator - (const Point& rhs) const { return Point(x-rhs.x, y-rhs.y); }
    Point operator * (const double& k) const { return Point(x*k, y*k); }
    Point operator / (const double& k) const { return Point(x/k, y/k); }
    bool operator < (const Point& rhs) const { return x < rhs.x || (x==rhs.x && y<rhs.y); }
    bool operator == (const Point& rhs) const {return sgn(x - rhs.x) == 0 && sgn(y - rhs.y) == 0; }
    Point turn(double rad) { return Point(x*cos(rad)-y*sin(rad), x*sin(rad)+y*cos(rad)); }
    void scan() { scanf("%lf%lf", &x, &y); }
};
typedef Point Vector;

double dot(Vector x, Vector y) { return x.x*y.x + x.y*y.y; }
double length(Vector x) { return sqrt(dot(x, x)); }
double cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }


Point LineProjection(Point P, Point A, Point B) {
    Vector v = B - A;
    return A + v * (dot(P-A, v) / dot(v, v));
}
Point LineReflection(Point P, Point A, Point B) {
    Point proj = LineProjection(P, A, B);
    return proj + proj - P;
}

int Clockwise(Point O, Point A, Point B) {
    /* Clockwise: -1
       Counterclockwise: 1
       Otherwise: 0
    */
    return sgn(cross(A - O, B - O));
}

void SegCheck(Point a, Point b, Point p) {
    Vector d = b - a, e = p - a;
    if(sgn(dot(d, e)) == -1) puts("ONLINE_BACK");
    else if(sgn(length(e) - length(d)) == 1) puts("ONLINE_FRONT");
    else puts("ON_SEGMENT");
}

int JudgeLLParOrth(Point a1, Point a2, Point b1, Point b2) {
    /* 2: parallel
       1: orthogonal
       0: otherwise
    */
    Vector v = a2 - a1, w = b2 - b1;
    if(sgn(cross(v, w)) == 0) return 2;
    if(sgn(dot(v, w)) == 0) return 1;
    return 0;
}

bool CheckSSProperIntersection(Point a1, Point a2, Point b1, Point b2) {
    double c1 = cross(a1 - b1, b2 - b1), c2 = cross(a2 - b1, b2 - b1);
    double c3 = cross(b1 - a1, a2 - a1), c4 = cross(b2 - a1, a2 - a1);
    return sgn(c1) * sgn(c2) == -1 && sgn(c3) * sgn(c4) == -1;
}
bool OnSeg(Point P, Point A, Point B) {
    Vector v = B - P, w = A - P;
    if(sgn(cross(v, w)) != 0) return false;
    return sgn(dot(v, w)) == -1;
}

bool CheckSSIntersection(Point a1, Point a2, Point b1, Point b2) {
    if(a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2) return true;
    if(OnSeg(a1, b1, b2) || OnSeg(a2, b1, b2) || OnSeg(b1, a1, a2) || OnSeg(b2, a1, a2))
        return true;
    return CheckSSProperIntersection(a1, a2, b1, b2);
}

Point LLIntersection(Point a1, Point a2, Point b1, Point b2) {
    Vector v = a2 - a1, w = b2 - b1, u = a1 - b1;
    double t1 = cross(w, u) / cross(v, w);
    return a1 + v * t1;
}

Point LLInt(Point P, Vector v, Point Q, Vector w) {
    Vector u = P - Q;
    double t = cross(w, u) / cross(v, w);
    return P + v * t;
}

int main() {
    Point a1, a2, b1, b2, res;
    int q; scanf("%d", &q);
    while(q--) {
        a1.scan(), a2.scan();
        b1.scan(), b2.scan();
        res = LLIntersection(a1, a2, b1, b2);
        printf("%.11f %.11f\n", res.x, res.y);
    }
    
    return 0;
}


Measured memory_bytes: 3224