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 <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
using Point = complex<double>;

#define X real()
#define Y imag()
double dot(Point a, Point b) {
    return (a.X * b.X + a.Y * b.Y);
}
using Line = pair<Point, Point>;
Point Projection(Line s, Point p) {
    Point vase = s.second - s.first;
    p -= s.first;
    return s.first + dot(p, vase) / norm(vase) * vase;
}
Point Reflection(Line s, Point p) {
    return p + (Projection(s, p) - p) * 2.0;
}
double cross(Point a, Point b) {
    return a.X * b.Y - a.Y * b.X;
}
int ccw(Point a, Point b, Point c) {
    if (cross(b - a, c - a) > EPS)return 1;
    if (cross(b - a, c - a) < -EPS)return -1;
    if (dot(b - a, c - a) < -EPS)return 2;
    if (abs(b - a) + EPS < abs(c - a))return -2;
    return 0;
}
bool isOrthogonal(Line a, Line b) {
    return dot(a.second - a.first, b.second - b.first) ? 0 : 1;
}
bool isParallel(Line a, Line b) {
    return cross(a.second - a.first, b.second - b.first) ? 0 : 1;
}
bool isCross(Line a, Line b) {
    if (ccw(a.first, a.second, b.first) * ccw(a.first, a.second, b.second)<=0 and
        ccw(b.first, b.second, a.first) * ccw(b.first, b.second, a.second)<=0) {
        return true;
    }
    return false;
}
Point CrossPoint(Line a, Line b) {
    double x, d;
    Point p1, p2, p3, p4;
    p1 = a.first;
    p2 = a.second;
    p3 = b.first;
    p4 = b.second;
    x = (p4.Y - p3.Y) * (p4.X - p1.X) - (p4.X - p3.X) * (p4.Y - p1.Y);
    d = (p4.Y - p3.Y) * (p2.X - p1.X) - (p4.X - p3.X) * (p2.Y - p1.Y);
    return p1 + x / d * (p2 - p1);

}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Point p1, p2, p3, p4;
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        double x1, x2, y1, y2, x3, x4, y3, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        p1 = Point(x1, y1);
        p2 = Point(x2, y2);
        p3 = Point(x3, y3);
        p4 = Point(x4, y4);
        Line l1 = Line(p1, p2), l2 = Line(p3, p4);
        printf("%.9f %.9f\n",CrossPoint(l1, l2).X,CrossPoint(l1, l2).Y);
    }
    return 0;

}