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>
using namespace std;
#include<cstdio>
#include<cmath>

struct Point{ double x, y; };

Point set_p(double a, double b)
{
    Point p;
    p.x = a; p.y = b;
    return p;
}

struct Vector{ double vx, vy; };

Vector set_v(const Point &p1, const Point &p2)
{
    Vector v;
    v.vx = p2.x - p1.x;
    v.vy = p2.y - p1.y;
    return v;
}

double dot(const Vector &v1, const Vector &v2)
{
    return (v1.vx * v2.vx) + (v1.vy * v2.vy);
}

double cross(const Vector &v1, const Vector &v2)
{
    return (v1.vx * v2.vy) - (v1.vy * v2.vx);
}

double cross0(const Point &P0, const Point &P1)
{
	return (P0.x * P1.y) - (P1.x * P0.y);
}

double onenorm(const Vector &v)
{
    return abs(v.vx) + abs(v.vy);
}

int ccw(const Point &P0, const Point &P1, const Point &P2)
{
    Vector V1 = set_v(P0, P1);
    Vector V2 = set_v(P0, P2);
    double c = cross(V1, V2);
    if(c > 0){ return 1; }else if(c < 0){ return -1; }
    if(dot(V1, V2) < 0){ return -2; }
    if(onenorm(V1) < onenorm(V2)){ return 2; }
    return 0;
}

int intersect(const Point &P0, const Point &P1, const Point &P2, const Point &P3)
{
    if(ccw(P0, P1, P2) * ccw(P0, P1, P3) <= 0 && ccw(P2, P3, P0) * ccw(P2, P3, P1) <= 0){
        return 1;
    }else{
        return 0;
    }
}

int main()
{
    int q;
    double x0, y0, x1, y1, x2, y2, x3, y3;
    Vector V01, V23;
    Point P0, P1, P2, P3;
    double Area, a, b;
    double isx, isy;
    scanf("%d", &q);

    for(int i = 0; i < q; i++){
        scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
        P0 = set_p(x0, y0), P1 = set_p(x1, y1), P2 = set_p(x2, y2), P3 = set_p(x3, y3);
        V01 = set_v(P0, P1), V23 = set_v(P2, P3);
        Area = cross(V01, V23);
        a = cross0(P2, P3) / Area, b = cross0(P0, P1) / Area;
        isx = a * (x1 - x0) - b * (x3 - x2);
        isy = a * (y1 - y0) - b * (y3 - y2);
        printf("%.12f %.12f\n", isx, isy);
    }
    return 0;
}