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

using namespace std;

#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
  double x, y;
  Point() {};
  Point(double x, double y): x(x), y(y) {}

  Point operator + (const Point &p) { return Point(x + p.x, y + p.y); }
  Point operator - (const Point &p) { return Point(x - p.x, y - p.y); }
  Point operator * (double d) { return Point(d * x, d * y); }
  Point operator / (double d) { return Point(d / x, d / y); }

  bool operator < (const Point &p) const {
    return (x == p.x ? y < p.y : x < p.x);
  }

  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

  friend ostream& operator << (ostream &os, Point &p) {
    return os << "Point(" << p.x << ", " << p.y << ")";
  }
};

typedef Point Vector;

struct Segment {
  Point p0, p1;
};

double cross (Point p1, Point p2) {
  return p1.x * p2.y - p1.y * p2.x;
}

double norm(Point p) {
  return p.x * p.x + p.y * p.y;
}

double abs(Point p) {
  return sqrt(norm(p));
}

Point cross_point(Segment s0, Segment s1) {
  Vector base = s1.p1 - s1.p0;
  double h1 = abs(cross(base, s0.p0 - s1.p0)) / abs(base);
  double h2 = abs(cross(base, s0.p1 - s1.p0)) / abs(base);
  double t = h1 / (h1 + h2);
  return s0.p0 + (s0.p1 - s0.p0) * t;
}

int main() {
  int xs[4];
  int ys[4];
  Segment ss[2];

  int q; cin >> q;

  while (q--) {
    for (int i = 0; i < 4; i++) {
      cin >> xs[i];
      cin >> ys[i];
    }

    Segment s0;
    s0.p0 = Point(xs[0], ys[0]);
    s0.p1 = Point(xs[1], ys[1]);

    Segment s1;
    s1.p0 = Point(xs[2], ys[2]);
    s1.p1 = Point(xs[3], ys[3]);

    Point p = cross_point(s0, s1);
    cout << fixed << setprecision(10)
         << p.x << ' '
         << p. y << endl;
  }
}