#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

struct Point {
  double x;
  double y;
  
  Point(double xx = 0, double yy = 0) {
    x = xx;
    y = yy;
  }
  Point operator + (Point p) { return Point(x + p.x, y + p.y); } //演算子のオーバーロード
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double k) { return Point(x * k, y * k); }
  Point operator / (double k) { return Point(x / k, y / k ); }
  bool operator == (Point p1) {
    if(p1.x == x && p1.y == y)
      return true;
    else 
      return false;
  }

};

double norm(Point p0, Point p1) {
  return sqrt(pow(p1.x - p0.x, 2) + pow(p1.y - p0.y, 2));
}

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

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


double area_ratio(Point p0, Point p1, Point p2, Point p3) {
  double s1 = fabs( cross(p2, p0, p3) );
  double s2 = fabs( cross(p2, p3, p1) );
  return s1 / (s1 + s2);
}


/*
int positional_relationship(Point p0, Point p1, Point p2) {
  if(cross(p0, p1, p2) > 0) //反時計回り
    return 1;
  else if(cross(p0, p1, p2) < 0) //時計回り
    return -1;
  else if(dot(p0, p1, p2) < 0) //一直線上で反転向き
    return 2;
  else if(norm(p0, p1) < norm(p0, p2)) // 一直線上で同じ向き
    return -2;
  else //線分上に存在
    return 0;  
}

bool isIntersected(Point p0, Point p1, Point p2, Point p3) {
  if(positional_relationship(p0, p1, p2) * positional_relationship(p0, p1, p3) <= 0 && positional_relationship(p2, p3 ,p0) * positional_relationship(p2, p3, p1) <= 0)
    return true;
  return false;
};
*/

int main(void) {
  int q;
  cin >> q;
  Point p0, p1, p2, p3;

  for(int i = 0; i < q; i++) {
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    double k = area_ratio(p0, p1, p2, p3);
    printf("%.10f %.10f\n", p0.x + k * (p1.x - p0.x), p0.y + k * (p1.y - p0.y));
  }

}

### Prompt

Your task is to create a Cpp solution to the following 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

### Response

```cpp
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

struct Point {
  double x;
  double y;
  
  Point(double xx = 0, double yy = 0) {
    x = xx;
    y = yy;
  }
  Point operator + (Point p) { return Point(x + p.x, y + p.y); } //演算子のオーバーロード
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double k) { return Point(x * k, y * k); }
  Point operator / (double k) { return Point(x / k, y / k ); }
  bool operator == (Point p1) {
    if(p1.x == x && p1.y == y)
      return true;
    else 
      return false;
  }

};

double norm(Point p0, Point p1) {
  return sqrt(pow(p1.x - p0.x, 2) + pow(p1.y - p0.y, 2));
}

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

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


double area_ratio(Point p0, Point p1, Point p2, Point p3) {
  double s1 = fabs( cross(p2, p0, p3) );
  double s2 = fabs( cross(p2, p3, p1) );
  return s1 / (s1 + s2);
}


/*
int positional_relationship(Point p0, Point p1, Point p2) {
  if(cross(p0, p1, p2) > 0) //反時計回り
    return 1;
  else if(cross(p0, p1, p2) < 0) //時計回り
    return -1;
  else if(dot(p0, p1, p2) < 0) //一直線上で反転向き
    return 2;
  else if(norm(p0, p1) < norm(p0, p2)) // 一直線上で同じ向き
    return -2;
  else //線分上に存在
    return 0;  
}

bool isIntersected(Point p0, Point p1, Point p2, Point p3) {
  if(positional_relationship(p0, p1, p2) * positional_relationship(p0, p1, p3) <= 0 && positional_relationship(p2, p3 ,p0) * positional_relationship(p2, p3, p1) <= 0)
    return true;
  return false;
};
*/

int main(void) {
  int q;
  cin >> q;
  Point p0, p1, p2, p3;

  for(int i = 0; i < q; i++) {
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    double k = area_ratio(p0, p1, p2, p3);
    printf("%.10f %.10f\n", p0.x + k * (p1.x - p0.x), p0.y + k * (p1.y - p0.y));
  }

}

```