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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
struct point{
    double x,y;
};
bool cross(point a,point b,point c,point d){
    double ta=(c.x-d.x)*(a.y-c.y)+(c.y-d.y)*(c.x-a.x);
    double tb=(c.x-d.x)*(b.y-c.y)+(c.y-d.y)*(c.x-b.x);
    double tc=(a.x-b.x)*(c.y-a.y)+(a.y-b.y)*(a.x-c.x);
    double td=(a.x-b.x)*(d.y-a.y)+(a.y-b.y)*(a.x-d.x);
    return tc*td<0&&ta*tb<0;
}
bool parallel(point a,point b,point c,point d){
    return abs((b.y-a.y)*(d.x-c.x)-(d.y-c.y)*(b.x-a.x))<1e-10;
}
double area(point a,point b,point c){
    return abs((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x))/2;
}
bool collinear(point a,point b,point c){
    return area(a,b,c)<1e-10;
}
point crosspoint(point a,point b,point c,point d){
    if(parallel(a,b,c,d))return {1e9,1e9};
    double xp=((c.y*d.x-c.x*d.y)*(b.x-a.x)-(a.y*b.x-a.x*b.y)*(d.x-c.x))/((b.y-a.y)*(d.x-c.x)-(b.x-a.x)*(d.y-c.y));
    double yp=((c.y*d.x-c.x*d.y)*(b.y-a.y)-(a.y*b.x-a.x*b.y)*(d.y-c.y))/((b.y-a.y)*(d.x-c.x)-(b.x-a.x)*(d.y-c.y));
    return {xp,yp};
}
signed main(){
    int n;
    cin>>n;
    while(n--){
        point a,b,c,d;
        cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y;
        point p=crosspoint(a,b,c,d);
        printf("%.12lf %.12lf\n",p.x,p.y);
    }
    return 0;
}