#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

// common
#define X real()
#define Y imag()

using Vector2 = complex<double>;
using Line = pair<Vector2, Vector2>;
using Segment = pair<Vector2, Vector2>;
const double EPS = 1e-10;
const double PI = 3.14159265359;

bool equals(double a, double b){
    if(abs(a - b) < EPS){
        return true;
    }
    else{
        return false;
    }
}

// struct

struct Circle{
    Vector2 c;
    double r;
    Circle(Vector2 c, double r){
        this->c = c;
        this->r = r;
    }
};

// Vector2
double dot(Vector2 a, Vector2 b){
    return (a.X * b.X + a.Y * b.Y);
}

double cross(Vector2 a, Vector2 b){
    return (a.X * b.Y - a.Y * b.X);
}

Vector2 crossPoint(Line l1, Line l2){
    Vector2 v = l2.first;
    Vector2 base = l2.second - v;
    double d1 = abs(cross(base, l1.first - v));
    double d2 = abs(cross(base, l1.second - v));
    double t = d1 / (d1 + d2);
    return l1.first + (l1.second - l1.first) * t;
}

int main(){

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        Segment s1(Vector2(x0, y0), Vector2(x1, y1));
        Segment s2(Vector2(x2, y2), Vector2(x3, y3));
        Vector2 ans = crossPoint(s1, s2);
        cout << fixed << setprecision(9) << ans.X  << " " << ans.Y << endl;
    }

    return 0;
}
