#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define EPS 1e-8
#define equals(a,b) fabs((a) - (b)) < EPS

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct Point {
	double x, y;

	Point(double x=0, double y=0) : x(x), y(y) {}

	Point operator+(const Point &o) const { return Point(x+o.x, y+o.y); }

	Point operator-(const Point &o) const { return Point(x-o.x, y-o.y); }

	Point operator*(const double m) const { return Point(x*m, y*m); }

	Point operator/(const double d) const { return Point(x/d, y/d); }

	bool operator<(const Point &o) const { return x != o.x ? x < o.x : y < o.y; }

	bool operator==(const Point &o) const { return fabs(x-o.x) < EPS && fabs(y-o.y) < EPS; }

	double cross(const Point &o) const { return x * o.y - y * o.x; }

	double dot(const Point &o) const { return x * o.x + y * o.y; }

	double atan() const { return atan2(y, x); }

	double norm() const { return sqrt(dot(*this)); }

	double distance(const Point &o) const { return (o - (*this)).norm(); }

	double area(const Point &a,const Point &b) {
		Point p = a - (*this), p2 = b - (*this); 
		return p.cross(p2);
	}

	double area_abs(const Point &a,const Point &b) const {
		Point p = a - (*this), p2 = b - (*this);
		return fabs(p.cross(p2)) / 2.0;
	}	

	//??????ab?????????????????????????????????????????????????????????
	int between(const Point &a,const Point &b) {
		if(area(a,b) != 0) return 0;

		if(a.x != b.x)  return ((a.x <= x) && (x <= b.x)) || ((a.x >= x) && (x >= b.x));
		else return ((a.y <= y) && (y <= b.y)) || ((a.y >= y) && (y >= b.y));
	}      

	double distance_seg(const Point& a,const Point& b) {
		if((b-a).dot(*this-a) < EPS) {
			return (*this-a).norm();
		}
		if((a-b).dot(*this-b) < EPS) {
			return (*this-b).norm();
		}
		return abs((b-a).cross(*this-a)) / (b-a).norm();
	}
};

ostream& operator << (ostream& os, const Point& p) {
	os << "(" << p.x << ", " << p.y << ")";
	return os;
}

int ccw(Point a, Point b, Point c) {
	b = b-a;
	c = c-a;

	if(b.cross(c) > 0.0) return +1;	//conter clockwise
	if(b.cross(c) < 0.0) return -1;	//clockwise
	if(b.dot(c) < 0.0) return +2;	//a on Seg(b,c)
	if(b.norm() < c.norm()) return -2;	//b on Seg(a,c)
	return 0;	//c on Seg(a,b)
}

struct Seg {
	Point a,b;

	Seg() : a(Point(0, 0)), b(Point(0, 0)) {}

	Seg (Point a, Point b) : a(a),b(b) {}

	bool isOrthogonal(Seg &s) { return equals((b - a).dot(s.b - s.a),0.0); }

	bool isParallel(Seg &s) { return equals((b-a).cross(s.b - s.a),0.0); }

	bool isIntersect(Seg &s) {
		return ccw(a, b, s.a) * ccw(a, b, s.b) <= 0 && ccw(s.a, s.b, a) * ccw(s.a, s.b, b) <= 0;
	}

	double distance(Seg &s) {
		if((*this).isIntersect(s)) return 0.0;

		return min(min(a.distance_seg(s.a,s.b),b.distance_seg(s.a,s.b)),min(s.a.distance_seg(a,b),s.b.distance_seg(a,b)));
	}

	Point getCrossPoint(Seg &s) {
		Point p = s.b - s.a;
		double d = abs(p.cross(a-s.a));
		double d2 = abs(p.cross(b-s.a));

		double t = d / (d+d2);
		return a + (b-a)*t;
	}

	Point project(Point &p) {
		Point base = b - a;
		double t = base.dot(p-a) / base.dot(base);
		return a + base * t;
	}

	Point reflect(Point &p) {
		return p + (project(p) - p) * 2.0;
	}
};

ostream& operator << (ostream& os, const Seg& s) {
	os << "(" << s.a.x << ", " << s.a.y << ")-(" << s.b.x << "," << s.b.y << ")";
	return os;
}

int main() {
	int q;
	cin >> q;

	Seg s1, s2;
	rep(i, q) {
		cin >> s1.a.x >> s1.a.y >> s1.b.x >> s1.b.y >> s2.a.x >> s2.a.y >> s2.b.x >> s2.b.y;

		Point p = s1.getCrossPoint(s2);

		cout << fixed;
		cout.precision(20);
		cout << p.x << " " << p.y << endl;
	}

	return 0;
}

Measured memory_bytes: 1300