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

struct vec{
    double x,y;
    vec operator-(vec b){
        vec& a = *this;
        vec c;
        c.x=a.x-b.x; c.y=a.y-b.y;
        return c;
    }
    vec operator+(vec b){
        vec& a = *this;
        vec c;
        c.x=a.x+b.x; c.y=a.y+b.y;
        return c;
    }
    vec operator*(double d){
        vec& a = *this;
        vec c;
        c.x=a.x*d; c.y=a.y*d;
        return c;
    }
};

const double eps = 0.0000001;

double inner_product(vec& a, vec& b){
    return a.x*b.x+a.y*b.y;
}

double outer_product(vec& a, vec& b){
    return a.x*b.y-a.y*b.x;
}

vec interSection(vec (&p)[4]){
    vec p23=p[3]-p[2],p02=p[2]-p[0],p01=p[1]-p[0];
    double k = outer_product(p23,p02)/outer_product(p23,p01);
    return p[0]+p01*k;
}

int main(void){
    vec p[4];
    int q;
    cin >> q;
    cout.precision(10);
    cout << fixed;
    while(q--){
        for(auto& v : p) cin >> v.x >> v.y;
        vec v = interSection(p);
        cout << v.x << " " << v.y << endl;
    }
    return 0;
}