#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(args...); }

typedef long double db;
const db eps = 1e-8;
const db pi = acosl(-1.0);

int sgn(db x) {if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1;}

struct Point{
    db x, y;
    Point(){}
    Point(db x, db y) : x(x), y(y){}
    void input(){cin >> x >> y;}
    Point operator + (const Point &b) const{
        return Point(x + b.x, y + b.y);
    }
    Point operator - (const Point &b) const {
        return Point(x - b.x, y - b.y);
    }
    db operator ^ (const Point &b) const{
        return x * b.y - y * b.x;
    }
    db operator * (const Point &b) const{
        return x * b.x + y * b.y;
    }
    Point operator * (const db &k) const{
        return Point(x * k, y * k);
    }
    Point operator / (const db &k) const{
        return Point(x / k, y / k);
    }
};
struct Line{
    Point s, e;
    Line(){}
    Line(Point s, Point e) : s(s), e(e){}
    void input() {s.input(); e.input();}
    Point getSegCrossPoint(Line v) {
        db a1 = (v.e - v.s) ^ (s - v.s);
        db a2 = (v.e - v.s) ^ (e - v.e);
        db t = a2 - a1;
        return Point((s.x * a2 - e.x * a1) / t, (s.y * a2 - e.y * a1) / t);
    }
}l1, l2;

int main(){
#ifndef ONLINE_JUDGE
// freopen("i.in","r",stdin);
//  freopen("o.out","w",stdout);
#endif
    int T;scanf("%d", &T);
    while(T--){
        Point p;
        l1.input(); l2.input();
        p = l1.getSegCrossPoint(l2);
        cout << fixed << setprecision(10) << p.x <<' ' << p.y <<endl;
    }

    return 0;
}
