#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(register ll(i)=(ll)(a);(i)<=(ll)(b);++i)
const ll inf=1e9+7;
#define y1 _y_1_
#ifndef gc
	#define gc getchar
#endif
#ifndef pc
	#define pc putchar
#endif
inline ll read(){ll f=0,x=0;register char c=gc();while(!isdigit(c))f^=c=='-',c=gc();while(isdigit(c))x=(x<<3)+(x<<1)+(c^'0'),c=gc();return x=f?-x:x;}
inline ll read(ll&x){ll f=0;x=0;register char c=gc();while(!isdigit(c))f^=c=='-',c=gc();while(isdigit(c))x=(x<<3)+(x<<1)+(c^'0'),c=gc();return x=f?-x:x;}
inline void writeln(){pc('\n');}
inline void write(ll x){if(x<0)pc('-'),x=-x;if(x>9)write(x/10);pc(x%10+'0');}
inline void writeln(const ll&x){write(x),pc('\n');}
using namespace std;
namespace Computation_Geometry{
	const ld eps=1e-10;
	struct point{
		ld x,y;
		inline point(){x=y=0;}
		inline point(const ld&X,const ld&Y){x=X,y=Y;}
		inline friend point operator +(const point&A,const point&B){return point(A.x+B.x,A.y+B.y);}
		inline friend point operator -(const point&A,const point&B){return point(A.x-B.x,A.y-B.y);}
		inline friend point operator *(const point&A,const ld&k){return point(A.x*k,A.y*k);}
		inline friend point operator /(const point&A,const ld&k){return A*(1.0/k);}
	};
	struct vec{
		ld x,y;
		inline bool is_zero(){return (abs(x)<=eps)&(abs(y)<=eps);}
		inline void scan(){x=read(),y=read();}
		inline vec(){x=y=0;}
		inline vec(const ld&X,const ld&Y){x=X,y=Y;}
		inline friend vec operator +(const vec&A,const vec&B){return vec(A.x+B.x,A.y+B.y);}
		inline friend vec operator -(const vec&A,const vec&B){return vec(A.x-B.x,A.y-B.y);}
		inline friend vec operator *(const vec&A,const ld&k){return vec(A.x*k,A.y*k);}
		inline friend vec operator /(const vec&A,const ld&k){return A*(1.0/k);}
		inline ld len(){return sqrt(x*x+y*y);}
		inline ld len(const ll&X,const ll&Y){return sqrt((x-X)*(x-X)+(y-Y)*(y-Y));}
		inline ld k(){return (x==0)?inf:y/x;}
		inline ld k(const ll&X,const ll&Y){return (x==X)?inf:(y-Y)/(x-X);}
		inline friend ld Dot(const vec&A,const vec&B){return A.x*B.x+A.y*B.y;}
		inline friend ld Cross(const vec&A,const vec&B){return A.x*B.y-B.x*A.y;}
		inline friend ld Theta(vec A,vec B){return acos(Cross(A,B)/A.len()/B.len());}
		inline friend ll ccw(vec p0,vec p1,vec p2){
			p1=p1-p0,p2=p2-p0;
			if (Cross(p1,p2)>=eps) return 1;//COUNTER_CLOCKWISE
			else if (Cross(p1,p2)<-eps) return -1;//CLOCKWISE
			else if (Dot(p1,p2)<-eps) return 2;//ONLINE_BACK
			else if (p1.len()<p2.len())return -2;//ONLINE_FRONT
			return 0;//ON_SEGMENT
		}
	};
	struct line{
		ld A,B,C;
		inline line(){A=B=C=0;}
		inline line(const ld&_A,const ld&_B,const ld&_C){A=_A,B=_B,C=_C;}
		inline line(const ld&x1,const ld&y1,const ld&x2,const ld&y2){A=y2-y1,B=x1-x2,C=x2*y1-x1*y2;}
		inline line(const vec&_A,const vec&_B){A=_A.y-_B.y,B=_B.x-_A.x,C=Cross(_A,_B);}
		inline vec Vec(){return vec(A,B);}
		inline friend bool is_on_line(line A,point B){return abs(A.A*B.x+A.B*B.y+A.C)<=eps;}
		inline friend bool parallel(line A,line B){return abs(Cross(A.Vec(),B.Vec()))<=eps;}
		inline friend bool perpendicular(line A,line B){return abs(Dot(A.Vec(),B.Vec()))<=eps;}
		inline friend point intersection(const line A, const line B){return point(A.B*B.C-A.C*B.B,A.C*B.A-A.A*B.C)/(A.A*B.B-A.B*B.A);}
	};
	struct segment{
		ld x1,x2,y1,y2;
		inline segment(){x1=y1=x2=y2=0;}
		inline segment(const ld&X1,const ld&Y1,const ld&X2,const ld&Y2){x1=X1,y1=Y1,x2=X2,y2=Y2;}
		inline line Line(){return line(x1,y1,x2,y2);}
		inline friend bool is_on_segment(segment A,point B){
			if (!is_on_line(A.Line(),B)) return false;
			return ((A.x1<=B.x&&B.x<=A.x2)||(A.x2<=B.x&&B.x<=A.x1))&&((A.y1<=B.y&&B.y<=A.y2)||(A.y2<=B.y&&B.y<=A.y1));
		}
		inline friend bool is_intersected(segment A,segment B){
			vec a=vec(A.x1,A.y1),b=vec(A.x2,A.y2),c=vec(B.x1,B.y1),d=vec(B.x2,B.y2);
			return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
		}
	};
}
using namespace Computation_Geometry;
ll Q;
ld x1,y1,x2,y2;
segment s1,s2;
point p;
signed main(){
	read(Q);while (Q--){
		x1=read(),y1=read(),x2=read(),y2=read();
		s1=segment(x1,y1,x2,y2);
		x1=read(),y1=read(),x2=read(),y2=read();
		s2=segment(x1,y1,x2,y2);
		p=intersection(s1.Line(),s2.Line());
		printf("%.10Lf %.10Lf\n",p.x,p.y);
	}
	fclose(stdin);fclose(stdout);return 0;
}


Measured memory_bytes: 3228