#include <iostream>
#include <iomanip>

class Point{
public:
	double x, y;
	Point(){
		x = y = 0;
	}
	Point(double _x, double _y){
		x = _x;
		y = _y;
	}
};

class Segment{
public:
	Point begin, end;
	Segment(){
		begin = Point();
		end = Point();
	}
	Segment(Point _begin, Point _end){
		begin = _begin;
		end = _end;
	}
};

int SegmentsIntersectionPoint(Segment &a, Segment &b, Point &out){
	double d = (a.end.x - a.begin.x) * (b.end.y - b.begin.y) - (a.end.y - a.begin.y) * (b.end.x - b.begin.x);
	double s = (b.end.y - b.begin.y) * (b.begin.x - a.begin.x) - (b.end.x - b.begin.x) * (b.begin.y - a.begin.y);
	double t = (a.end.y - a.begin.y) * (b.begin.x - a.begin.x) - (a.end.x - a.begin.x) * (b.begin.y - a.begin.y);
	
	if(d == 0){
		//????????§???????????????
		return 1;
	}
	
	out.x = a.begin.x + s * (a.end.x - a.begin.x) / d;
	out.y = a.begin.y + s * (a.end.y - a.begin.y) / d;
	
	return 0;
}

int main(){
	int n;
	int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
	Point insc;
	Segment a, b;
	
	std::cin >> n;
	for(int i=0;i<n;++i){
		std::cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;
		a = Segment(Point(xp0, yp0), Point(xp1, yp1));
		b = Segment(Point(xp2, yp2), Point(xp3, yp3));
		
		SegmentsIntersectionPoint(a, b, insc);
		
		std::cout << std::setprecision(15) << insc.x << " " << insc.y << std::endl;
	}
	
	return 0;
}