#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<assert.h>
#include<set>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<iostream>
#include<bitset>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define rep(i,j,k) for(int i=(int)(j);i<=(int)(k);i++)
#define per(i,j,k) for(int i=(int)(j);i>=(int)(k);i--)
using namespace std;
typedef long long LL;
//template
typedef double db;
const db eps=1e-10;
const db pi=acosl(-1.0);
int sign(db x){if(x<-eps)return -1;if(x>eps)return 1;return 0;}
int cmp(db x,db y){return sign(x-y);}
bool inmid(db x,db l,db r){return cmp(x,l)*cmp(x,r)<=0;}
struct po{
	db x,y;
	po(db _x=0,db _y=0):x(_x),y(_y){}
	void read(){scanf("%lf%lf",&x,&y);}
};
po operator +(const po &a,const po &b){return po(a.x+b.x,a.y+b.y);}
po operator -(const po &a,const po &b){return po(a.x-b.x,a.y-b.y);}
po operator *(const po &a,const db &b){return po(a.x*b,a.y*b);}
po operator /(const po &a,const db &b){return po(a.x/b,a.y/b);}
db operator *(const po &a,const po &b){return a.x*b.x+a.y*b.y;}
db operator ^(const po &a,const po &b){return a.x*b.y-a.y*b.x;}
db mo2(po a){return a*a;}
db mo(po a){return sqrt(a*a);}
po proj(po x,po y){//proj x to y
	return y*((x*y)/mo2(y));
}
po refl(po x,po y){//refl x from y
	return proj(x,y)*2-x;
}
bool onseg(po x,po l,po r){
	return (sign((x-l)^(r-l))==0)&&inmid(x.x,l.x,r.x)&&inmid(x.y,l.y,r.y);
}
bool inter(db l1,db r1,db l2,db r2){
	if(cmp(l1,r1)==1)swap(l1,r1);
	if(cmp(l2,r2)==1)swap(l2,r2);
	return cmp(min(r1,r2),max(l1,l2))>=0;
}
bool checkss(po a,po b,po c,po d){
	return sign((b-a)^(c-a))*sign((b-a)^(d-a))<=0&&sign((d-c)^(a-c))*sign((d-c)^(b-c))<=0&&inter(a.x,b.x,c.x,d.x)&&inter(a.y,b.y,c.y,d.y);
}
po getll(po a,po b,po c,po d){
	db u=((b-a)^(c-a));
	db v=((d-a)^(b-a));
	return (c*v+d*u)/(u+v);
}
//template
int main(){
	int t;scanf("%d",&t);
	while(t--){
		po a,b,c,d;
		a.read();b.read();c.read();d.read();
		po w=getll(a,b,c,d);
		printf("%.10lf %.10lf\n",w.x,w.y);
	}
	return 0;
}




