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<cmath>
#include<vector>

using namespace std;

const long double EPS = 1e-10;

class Point{
    public: 
    long double x,y;
    Point(long double x = 0.0, long double y = 0.0): x(x), y(y) {}
    Point operator + (Point p) const { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) const { return Point(x-p.x, y-p.y); }
    Point operator * (long double a) const { return Point(x*a, y*a); }
    Point operator / (long double a) const { return Point(x/a, y/a); }
    bool operator < (const Point &p) const { return (x != p.x ? x < p.x : y < p.y); }
    bool operator == (const Point &p) const { return fabsl(x - p.x) < EPS && fabsl(y - p.y) < EPS; }
    long double abs() const { return sqrt(norm()); }
    long double norm() const { return x*x + y*y; }
    long double dot(Point p) const { return x*p.x + y*p.y; }
    long double cross(Point p) const { return x*p.y - y*p.x; }   
};

class Segment{
    public: 
    Point p,q;
    Segment(Point p, Point q): p(p), q(q) {}
};

typedef Point Vector;

Point getCrossPoint(Segment s1, Segment s2){
    Vector base = s2.q - s2.p;
    long double d1 = abs(base.cross(s1.p - s2.p));
    long double d2 = abs(base.cross(s1.q - s2.p));
    long double t = d1 / (d1+d2);
    return s1.p + (s1.q - s1.p) * t;
}

int main(){
    int n;
    cin >> n;
    vector<Point> ps(4, Point());
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            cin >> ps[j].x >> ps[j].y;
        }
        Segment s1 = Segment(ps[0], ps[1]);
        Segment s2 = Segment(ps[2], ps[3]);
        Point cross_point = getCrossPoint(s1, s2);
        printf("%.10Lf %.10Lf\n", cross_point.x, cross_point.y);
    }
}