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<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
static const double EPS = pow(10,-10);
typedef long long ll;
static int COUNTER_CLOCKWISE = 1;
static int CLOCKWISE = -1;
static int ONLINE_BACK = 2;
static int ONLINE_FRONT = -2;
static int ON_SEGMENT = 0;




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

  Vector2 operator + (Vector2 v) {
    return Vector2(x + v.x , y + v.y);
  }
  Vector2 operator - (Vector2 v) {
    return Vector2(x - v.x , y - v.y);
  }

  Vector2 operator * (double d){
    return Vector2(d*x, d*y);
  }

  double norm(){
    return pow(x,2) + pow(y,2);
  }

};

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

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

Vector2 projection(Vector2 a, Vector2 b, Vector2 p){
  Vector2 base = b - a;
  Vector2 hypo = p - a;
  double norm_base = pow(base.x,2) + pow(base.y,2);

  Vector2 x;
  x = a + base*(dot(hypo,base) / norm_base);
  return x;
}

Vector2 refrection(Vector2 a, Vector2 b, Vector2 p){
  Vector2 v, p_projection;
  p_projection = projection(a,b,p); 
  v = p_projection + (p_projection - p);
  return v;
}

int ccw(Vector2 a, Vector2 b, Vector2 p){
  Vector2 hypo = p - a;
  Vector2 base = b - a;
  if(cross(base,hypo) > EPS) return COUNTER_CLOCKWISE;
  if(cross(base,hypo) < -EPS) return CLOCKWISE;
  if(dot(base,hypo) < -EPS) return ONLINE_BACK;
  if(hypo.norm() > base.norm()) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersect(Vector2 a,Vector2 b,Vector2 p,Vector2 q){
  int t1, t2;
  t1 =ccw(a,b,p)*ccw(a,b,q);
  t2 =ccw(p,q,a)*ccw(p,q,b);
  if(t1 <= 0 && t2 <= 0) return true;
  else return false;
}

Vector2 crossPoint(Vector2 a,Vector2 b,Vector2 p,Vector2 q){
  Vector2 base, hypo_1, hypo_2, v;
  base = b-a;
  hypo_1 = p-a;
  hypo_2 = q-a;
  double d1 = abs(cross(base, hypo_1)); 
  double d2 = abs(cross(base, hypo_2));
  double ratio = d1/(d1+d2);
  v = p + (hypo_2 - hypo_1)*ratio;
  return v;
}




int main(){
  Vector2 a,b,p,q,v;
  int queri;
  cin >> queri;
  rep(i,queri){
    cin >> a.x >> a.y >> b.x >> b.y;
    cin >> p.x >> p.y >> q.x >> q.y;
    v = crossPoint(a,b,p,q);
    cout << fixed << setprecision(10);
    cout << v.x << " " << v.y;
    cout << endl;
  }
  return 0;
}