#ifndef ___Geometry_Library
#define ___Geometry_Library

// ------ Includes ------ //
#include <cmath>
#include <complex>
#include <utility>
#include <algorithm>

// ------ Defines ------ //
typedef long double GType;
typedef std::complex<GType> Point;
typedef std::pair<Point, Point> Segment;

// ------ Constants ------ //
const GType EPS = 1.0e-10L;

// ------ Functions Level 1 ------ //
GType dot(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).real();
}
GType cross(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).imag();
}
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point v1 = p2 - p1, v2 = p3 - p1;
	if (cross(v1, v2) > EPS) return +1;
	if (cross(v1, v2) < -EPS) return -1;
	if (dot(v1, v2) < -EPS) return +2;
	if (std::norm(v1) < std::norm(v2)) return -2;
	return 0;
}

// ------ Functions Level 2 ------ //
bool intersect(const Segment& s1, const Point& p1, bool segflag) {
	if (!segflag) return std::abs(cross(s1.second - p1, s1.first - p1)) < EPS;
	return (std::abs(s1.first - p1) + std::abs(s1.second - p1) - std::abs(s1.second - s1.first)) < EPS;
}
bool intersect(const Segment& s1, const Segment& s2, bool segflag) {
	if (!segflag) return cross(s1.second - s1.first, s2.first - s1.first) * cross(s1.second - s1.first, s2.second - s1.first) < EPS;
	return (ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second)) <= 0 && (ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second)) <= 0;
}
Point crosspoint(const Segment& s1, const Segment& s2) {
	GType r1 = cross(s1.second - s1.first, s2.second - s2.first);
	GType r2 = cross(s1.second - s1.first, s1.second - s2.first);
	if (std::abs(r1) < EPS && std::abs(r2) < EPS) return s2.first;
	return s2.first + r2 / r1 * (s2.second - s2.first);
}

#endif

#include <iomanip>
#include <iostream>
using namespace std;
int q, xa, ya, xb, yb; Segment s1, s2;
int main() {
	cin >> q;
	while (q--) {
		cin >> xa >> ya >> xb >> yb; s1 = make_pair(Point(xa, ya), Point(xb, yb));
		cin >> xa >> ya >> xb >> yb; s2 = make_pair(Point(xa, ya), Point(xb, yb));
		Point ret = crosspoint(s1, s2);
		cout << fixed << setprecision(15) << ret.real() << ' ' << ret.imag() << endl;
	}
	return 0;
}