Problem: For given two segments s1 and s2, print the coordinate of the cross point of them.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
* The given segments have a cross point and are not in parallel.

Input

The entire input looks like:


q (the number of queries)
1st query
2nd query
...
qth query


Each query consists of integer coordinates of end points of s1 and s2 in the following format:


xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3


Output

For each query, print the coordinate of the cross point. The output values should be in a decimal fraction with an error less than 0.00000001.

Example

Input

3
0 0 2 0 1 1 1 -1
0 0 1 1 0 1 1 0
0 0 1 1 1 0 0 1


Output

1.0000000000 0.0000000000
0.5000000000 0.5000000000
0.5000000000 0.5000000000

Solution (in CPP):

Solution:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#define eps 1e-14
#define double long double
using namespace std;
struct point{
	double x,y;
	void read(){scanf("%Lf%Lf",&x,&y);}
	void write(){printf("%.10Lf %.10Lf\n",x,y);}
	point(double X=0.0,double Y=0.0):x(X),y(Y){}
	point operator +(const point a)const{return point(x+a.x,y+a.y);}
	point operator -(const point a)const{return point(x-a.x,y-a.y);}
	point operator *(double a)const{return point(x*a,y*a);}
	point operator /(double a)const{return point(x/a,y/a);}
	bool operator ==(const point a)const{return abs(x-a.x)<=eps && abs(y-a.y)<=eps;}
};
double dis(point a){return sqrt(a.x*a.x+a.y*a.y);}
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
double cross3(point o,point a,point b){return cross(a-o,b-o);}
bool jiao(point a,point b,point c,point d)
{
	if(min(a.x,b.x)>max(c.x,d.x) || min(a.y,b.y)>max(c.y,d.y)) return false;
	if(min(c.x,d.x)>max(a.x,b.x) || min(c.y,d.y)>max(a.y,b.y)) return false;
	if(cross3(a,b,c)*cross3(a,b,d)>0) return false;
	if(cross3(c,d,a)*cross3(c,d,b)>0) return false;
	return true;
}
void make_rand(double &x){x=x+(1ll*rand()%10+1)/10.0*eps;}
struct Line{
	point a,b;
	void read(){a.read();b.read();}
	bool operator &&(const Line u){return jiao(a,b,u.a,u.b);}
	point operator &(const Line u)
	{
		if(a==u.a || a==u.b) return a;
		if(b==u.a || b==u.b) return b;
		double x1=a.x,x2=b.x,x3=u.a.x,x4=u.b.x;
		double y1=a.y,y2=b.y,y3=u.a.y,y4=u.b.y;
		if(x3==x4) return point(x3,(y2-y1)*x3/(x2-x1)+(y1*x2-x1*y2)/(x2-x1));
		if(x1==x2) return point(x1,(y4-y3)*x1/(x4-x3)+(y3*x4-x3*y4)/(x4-x3));
		make_rand(x2);
		double x=((y3*x4-y4*x3)*(x2-x1)-(y1*x2-y2*x1)*(x4-x3))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
		double y=(y2-y1)*x/(x2-x1)+(y1*x2-x1*y2)/(x2-x1);
		return point(x,y);
	}
};
int main()
{
	int n;
	scanf("%d",&n);
	
	srand(n);
	for(int i=1;i<=n;i++)
	{
		Line a,b;
		a.read();b.read();
		(a&b).write();
	}
	return 0;
}