#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const double EPS = 1e-8;

int dcmp(double d) {
    if (fabs(d) < EPS) {
        return 0;
    }
    return d < 0? -1 : 1;
}

struct Vector {
    double x, y;
    Vector(double x=0, double y=0): x(x), y(y){
    }
};

typedef Vector Point;

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

Vector operator+(const Vector& a, const Vector& b) {
    return Vector(a.x + b.x, a.y + b.y);
}

Vector operator*(const Vector& a, const double p) {
    return Vector(a.x * p, a.y * p);
}


bool intersectProp(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    double c1 = cross(a2 - a1, b1 - a1);
    double c2 = cross(a2 - a1, b2 - a1);
    double c3 = cross(b2 - b1, a1 - b1);
    double c4 = cross(b2 - b1, a2 - b1);
    
    return dcmp(c1 * c2) == -1 && dcmp(c3 * c4) == -1;
}

bool onSegment(const Point& a, const Point& b, const Point& p) {
    Vector pa = a - p;
    Vector pb = b - p;
    return dcmp(cross(pa, pb)) == 0 && dcmp(dot(pa, pb)) <= 0;
}

bool intersect(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    return intersectProp(a1, a2, b1, b2) || onSegment(a1, a2, b1) 
            || onSegment(a1, a2, b2) || onSegment(b1, b2, a1) || onSegment(b1, b2, a2);
}

Point lineIntesection(const Point& p, const Vector& v, const Point& q, const Vector& w) {
    Vector u = p - q;
    return p + v * (cross(w, u) / cross(v, w)); 
}

int main() {
    Point points[4];
    int q;
    cin >> q;
    for (int kase = 0; kase < q; kase++) {
        for (int i = 0; i < 4; i++) {
            cin >> points[i].x >> points[i].y;
        }
        Vector v1 = points[1] - points[0];
        Vector v2 = points[3] - points[2];

        Vector p = lineIntesection(points[0], v1, points[2], v2);
        
        cout << fixed << setprecision(8) << p.x << " " << p.y << endl;
    }
   
    return 0;
}
### Prompt

Construct a CPP code solution to the problem outlined:

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 <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const double EPS = 1e-8;

int dcmp(double d) {
    if (fabs(d) < EPS) {
        return 0;
    }
    return d < 0? -1 : 1;
}

struct Vector {
    double x, y;
    Vector(double x=0, double y=0): x(x), y(y){
    }
};

typedef Vector Point;

double dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}

double cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

Vector operator-(const Vector& a, const Vector& b) {
    return Vector(a.x - b.x, a.y - b.y);
}

Vector operator+(const Vector& a, const Vector& b) {
    return Vector(a.x + b.x, a.y + b.y);
}

Vector operator*(const Vector& a, const double p) {
    return Vector(a.x * p, a.y * p);
}


bool intersectProp(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    double c1 = cross(a2 - a1, b1 - a1);
    double c2 = cross(a2 - a1, b2 - a1);
    double c3 = cross(b2 - b1, a1 - b1);
    double c4 = cross(b2 - b1, a2 - b1);
    
    return dcmp(c1 * c2) == -1 && dcmp(c3 * c4) == -1;
}

bool onSegment(const Point& a, const Point& b, const Point& p) {
    Vector pa = a - p;
    Vector pb = b - p;
    return dcmp(cross(pa, pb)) == 0 && dcmp(dot(pa, pb)) <= 0;
}

bool intersect(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    return intersectProp(a1, a2, b1, b2) || onSegment(a1, a2, b1) 
            || onSegment(a1, a2, b2) || onSegment(b1, b2, a1) || onSegment(b1, b2, a2);
}

Point lineIntesection(const Point& p, const Vector& v, const Point& q, const Vector& w) {
    Vector u = p - q;
    return p + v * (cross(w, u) / cross(v, w)); 
}

int main() {
    Point points[4];
    int q;
    cin >> q;
    for (int kase = 0; kase < q; kase++) {
        for (int i = 0; i < 4; i++) {
            cin >> points[i].x >> points[i].y;
        }
        Vector v1 = points[1] - points[0];
        Vector v2 = points[3] - points[2];

        Vector p = lineIntesection(points[0], v1, points[2], v2);
        
        cout << fixed << setprecision(8) << p.x << " " << p.y << endl;
    }
   
    return 0;
}
```