#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

template<class T>
struct Vec2
{
	Vec2(){}
	Vec2(T _x, T _y) : x(_x), y(_y) {}

	Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
	Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
	Vec2 operator*(T s) const { return Vec2(x*s, y*s); }
	Vec2 operator/(T s) const { return Vec2(x/s, y/s); }
	T dot(const Vec2& rhs) const { return x*rhs.x + y*rhs.y; }
	T cross(const Vec2& rhs) const { return x*rhs.y - y*rhs.x; }
	T sqlength() const { return x*x + y*y; }
	double length() const { return sqrt(sqlength()); }
	bool operator<(const Vec2& rhs) const
	{
		if (x != rhs.x) return x < rhs.x;
		return y < rhs.y;
	}

	T x;
	T y;
};

template<class T>
T cross(const Vec2<T> &O, const Vec2<T> &A, const Vec2<T> &B)
{
	return (A - O).cross(B - O);
}

int main()
{
	typedef Vec2<double> Vec;

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		Vec P[4];
		for (int j = 0; j < 4; j++) {
			cin >> P[j].x >> P[j].y;
		}

		double c1 = cross(P[0], P[1], P[2]);
		double c2 = cross(P[0], P[1], P[3]);
		Vec ans = P[2] + (P[3] - P[2])*c1 / (c1 - c2);
		printf("%.10f %.10f\n", ans.x, ans.y);
	}
	return 0;
}
