#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
#define EPS (1e-10)

static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

struct Point { double x, y; };//点
struct Segment { Point p1, p2; };//線
double dot(Point a, Point b) {//内積
    return a.x * b.x + a.y * b.y;
}
double cross(Point a, Point b) {//外積
    return a.x * b.y - a.y * b.x;
}
double norm(Point a) {
    return a.x * a.x + a.y * a.y;
}
double absv(Point a) {
    return sqrt(norm(a));
}
Point project(Segment s, Point p) {
    Point base, q;
    Point ans;
    base.x = s.p2.x - s.p1.x;
    base.y = s.p2.y - s.p1.y;
    q.x = p.x - s.p1.x;
    q.y = p.y - s.p1.y;
    double r = dot(q, base) / norm(base);
    ans.x = s.p1.x + base.x * r;
    ans.y = s.p1.y + base.y * r;
    return ans;
}
Point reflect(Segment s, Point p) {
    Point ans;
    ans.x = p.x + (project(s, p).x - p.x) * 2.0;
    ans.y = p.y + (project(s, p).y - p.y) * 2.0;
    return ans;
}
/*double getPointDistance(Point a, Point b) {
    Point ans;
    ans.x = a.x - b.x;
    ans.y = a.y - b.y;
    absv(ans);
}
double getDistanceLP(Segment l, Point p) {
    Point tmp, tmp2, ans;
    tmp.x = l.p2.x - l.p1.x;
    tmp.y = l.p2.y - l.p1.y;
    tmp2.x = p.x - l.p1.x;
    tmp2.y = p.y - l.p1.y;
    return absv(cross(tmp, tmp2) / absv(tmp));
}
double getDistanceSP(Segment s, Point p) {
    Point t1, t2, t3, t4;
    t1.x = s.p2.x - s.p1.x;
    t1.y = s.p2.y - s.p1.y;
    t2.x = p.x - s.p1.x;
    t2.y = p.y - s.p1.y;
    t3.x = s.p1.x - s.p2.x;
    t3.y = s.p1.y - s.p2.y;
    t4.x = p.x - s.p2.x;
    t4.y = p.y - s.p2.y;
    if (dot(t1, t2) < 0.0)return absv(t2);
    if (dot(t3, t4) < 0.0)return absv(t4);
    return getDistanceLP(s, p);
}*/
int ccw(Point p0,Point p1,Point p2){
    Point a,b;
    a.x=p1.x-p0.x;
    a.y=p1.y-p0.y;
    b.x=p2.x-p0.x;
    b.y=p2.y-p0.y;
    if(cross(a,b)>EPS)return COUNTER_CLOCKWISE;
    if(cross(a,b)<(-EPS))return CLOCKWISE;
    if(dot(a,b)<(-EPS))return ONLINE_BACK;
    if(norm(a)<norm(b))return ONLINE_FRONT;
    
    return ON_SEGMENT;
}
bool intersect(Point p1,Point p2,Point p3,Point p4){
    return(ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 && ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}
bool intersectS(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}
Point getCrossPoint(Segment s1,Segment s2){
    Point base,a,b,c;
    base.x=s2.p2.x-s2.p1.x;
    base.y=s2.p2.y-s2.p1.y;
    a.x=s1.p1.x-s2.p1.x;
    a.y=s1.p1.y-s2.p1.y;
    b.x=s1.p2.x-s2.p1.x;
    b.y=s1.p2.y-s2.p1.y;
    double d1=abs(cross(base,a));
    double d2=abs(cross(base,b));
    double t=d1/(d1+d2);
    c.x=s1.p1.x+(s1.p2.x-s1.p1.x)*t;
    c.y=s1.p1.y+(s1.p2.y-s1.p1.y)*t;
    return c;
}
/*double getDistance(Segment s1,Segment s2){
    if(intersectS(s1,s2))return 0.0;
    return min(min(getDistanceSP(s1,s2.p1)),getDistanceSP(s1,s2.p2)),min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}*/

int main(void) {
    Segment a,b;
    Point ans;
    int n;cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a.p1.x >> a.p1.y >> a.p2.x >> a.p2.y;
        cin >> b.p1.x >> b.p1.y >> b.p2.x >> b.p2.y;
        ans=getCrossPoint(a,b);
        cout << fixed << setprecision(10) << ans.x << " " << ans.y << endl;
    }
    return 0;
}



Measured memory_bytes: 3280