#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    Point operator + (Point p){
        return Point(x+p.x,y+p.y);
    }
 
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
 
    Point operator * (double k){
        return Point(k*x,k*y);
    }
 
 	Point operator / (double k){
 		return Point(x/k,y/k);
 	}

    bool operator<(const Point &p)const{
        return x!=p.x?x<p.x:y<p.y;
    }
 
};
double dot(Point p, Point q){
    return p.x*q.x+p.y*q.y;
}
 
double cross(Point p,Point q){
    return p.x*q.y-q.x*p.y;
}
 
double norm(Point p){
    return p.x*p.x+p.y*p.y;
}
 
double pabs(Point p){
    return sqrt(norm(p));
}
typedef vector<Point> Polygon;
struct Line : Polygon{
    Line(){}
    Line(Point p,Point q){
        PB(p);
        PB(q);  
    }
};
struct Circle{
    Point p; //中心点
    double r; //半径
    Circle(){}
    Circle(Point _p,double _r){
        p = _p;
        r = _r;
    }
};
int ccw(Point a,Point b,Point c){
    b = b-a;
    c = c-a;
    if(cross(b,c) > 0)return +1; //a→b で反時計に折れてc ccw
    if(cross(b,c) < 0)return -1; //a→b で時計に折れてc ccw
    if(dot(b,c) < 0)return +2; // c--a--b;
    if(pabs(b)<pabs(c))return -2; //a--b--c
    return 0; //a--c--b
}
bool intersectSS(Line l,Line m){
    //lとmが交差してるかどうか
    return (ccw(l[0],l[1],m[0])*ccw(l[0],l[1],m[1])<=0)&&
            (ccw(m[0],m[1],l[0])*ccw(m[0],m[1],l[1])<=0);
}

double TriangleArea(Point a,Point b,Point c){
	b = b - a;
	c = c - a;
	return fabs(cross(b,c))*0.5;
}

double VertexArea(Polygon v){
	double subArea = 0.0;
	rep(i,v.size()-1){
		subArea += TriangleArea(v[0],v[i],v[i+1]);
	}
}

Point crosspoint(Line l,Line m){
	if(intersectSS(l,m) == false)return Point(INF,INF);
	return m[0]+(m[1]-m[0])*cross(l[1]-l[0],l[1]-m[0])/cross(l[1]-l[0],m[1]-m[0]);
}

int main(){
	int Q;
	cin >> Q;
	while(Q--){
		Line l[2];
		rep(i,2){
			double x1,y1,x2,y2;
			cin >> x1 >> y1 >> x2 >> y2;
			l[i].PB(Point(x1,y1));
			l[i].PB(Point(x2,y2));
		}
		Point ans = crosspoint(l[0],l[1]);
		printf("%.10lf %.10lf\n",ans.x,ans.y);
	}
	return 0;
}
### Prompt

Generate a cpp solution to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    Point operator + (Point p){
        return Point(x+p.x,y+p.y);
    }
 
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
 
    Point operator * (double k){
        return Point(k*x,k*y);
    }
 
 	Point operator / (double k){
 		return Point(x/k,y/k);
 	}

    bool operator<(const Point &p)const{
        return x!=p.x?x<p.x:y<p.y;
    }
 
};
double dot(Point p, Point q){
    return p.x*q.x+p.y*q.y;
}
 
double cross(Point p,Point q){
    return p.x*q.y-q.x*p.y;
}
 
double norm(Point p){
    return p.x*p.x+p.y*p.y;
}
 
double pabs(Point p){
    return sqrt(norm(p));
}
typedef vector<Point> Polygon;
struct Line : Polygon{
    Line(){}
    Line(Point p,Point q){
        PB(p);
        PB(q);  
    }
};
struct Circle{
    Point p; //中心点
    double r; //半径
    Circle(){}
    Circle(Point _p,double _r){
        p = _p;
        r = _r;
    }
};
int ccw(Point a,Point b,Point c){
    b = b-a;
    c = c-a;
    if(cross(b,c) > 0)return +1; //a→b で反時計に折れてc ccw
    if(cross(b,c) < 0)return -1; //a→b で時計に折れてc ccw
    if(dot(b,c) < 0)return +2; // c--a--b;
    if(pabs(b)<pabs(c))return -2; //a--b--c
    return 0; //a--c--b
}
bool intersectSS(Line l,Line m){
    //lとmが交差してるかどうか
    return (ccw(l[0],l[1],m[0])*ccw(l[0],l[1],m[1])<=0)&&
            (ccw(m[0],m[1],l[0])*ccw(m[0],m[1],l[1])<=0);
}

double TriangleArea(Point a,Point b,Point c){
	b = b - a;
	c = c - a;
	return fabs(cross(b,c))*0.5;
}

double VertexArea(Polygon v){
	double subArea = 0.0;
	rep(i,v.size()-1){
		subArea += TriangleArea(v[0],v[i],v[i+1]);
	}
}

Point crosspoint(Line l,Line m){
	if(intersectSS(l,m) == false)return Point(INF,INF);
	return m[0]+(m[1]-m[0])*cross(l[1]-l[0],l[1]-m[0])/cross(l[1]-l[0],m[1]-m[0]);
}

int main(){
	int Q;
	cin >> Q;
	while(Q--){
		Line l[2];
		rep(i,2){
			double x1,y1,x2,y2;
			cin >> x1 >> y1 >> x2 >> y2;
			l[i].PB(Point(x1,y1));
			l[i].PB(Point(x2,y2));
		}
		Point ans = crosspoint(l[0],l[1]);
		printf("%.10lf %.10lf\n",ans.x,ans.y);
	}
	return 0;
}
```