#include <cstdio>
#include <cstring>
#include <cmath>
#define EPS 1e-10
using namespace std;

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0;
	return a+b;
}

struct P{
	double x,y;
	P(double xx=0,double yy=0){
		x=xx;
		y=yy;
	}
	P operator +(P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator -(P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator *(double d){
		return P(x*d,y*d);
	}
	P operator /(double d){
		return P(x/d,y/d);
	}
	double abs(){
		return sqrt(norm());
	}
	double norm(){
		return x*x+y*y;
	}
};

typedef P Vector;
struct Segment{
	P p1,p2;
	Segment(P pp1=P(),P pp2=P()){
		p1=pp1;
		p2=pp2;
	}
};

double dot(Vector a,Vector b){
	return add(a.x*b.x,a.y*b.y);
}

double cross(Vector a,Vector b){
	return add(a.x*b.y,-a.y*b.x);
}

P getCrossPoint(Segment s1,Segment s2){
	Vector base=s2.p2-s2.p1;
	double d1=abs(cross(base,s1.p1-s2.p1));
	double d2=abs(cross(base,s1.p2-s2.p1));
	double t=d1/(d1+d2);
	return s1.p1+(s1.p2-s1.p1)*t;
}

int main(void){
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		Segment s1,s2;
		scanf("%lf %lf",&s1.p1.x,&s1.p1.y);
		scanf("%lf %lf",&s1.p2.x,&s1.p2.y);
		scanf("%lf %lf",&s2.p1.x,&s2.p1.y);
		scanf("%lf %lf",&s2.p2.x,&s2.p2.y);
		P res=getCrossPoint(s1,s2);
		printf("%.10f %.10f\n",res.x,res.y);
	}
	return 0;
}