#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs(a - b) < EPS)

class Point{
public:
  double x, y;

  Point(double x = 0, double y = 0) : x(x), y(y) {}

  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 a){return Point(x * a, y * a);}
  Point operator / (double a){return Point(x / a, y / a);}

  double abs(){return sqrt(norm());}
  double norm(){return x * x + y * y;}

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

};

typedef Point Vector;

class Segment{
public:
  Point p1, p2;
  Segment(Point p1, Point p2): p1(p1), p2(p2){}
};

typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0): c(c), r(r){}
};

typedef vector<Point> Polygon;

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

Point reflect(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p0.x - p1.x, p0.y - p1.y);
  Vector v21 = Vector(p2.x - p1.x, p2.y - p1.y);
  double t = -1 * ((p2.x - p1.x) * (p1.x - p0.x) + (p2.y - p1.y) * (p1.y - p0.y)) / (pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
  return (v21 * t - v01) * 2 + p0;
}

Point project(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p0.x - p1.x, p0.y - p1.y);
  Vector v21 = Vector(p2.x - p1.x, p2.y - p1.y);
  double t = -1 * ((p2.x - p1.x) * (p1.x - p0.x) + (p2.y - p1.y) * (p1.y - p0.y)) / (pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2));
  return v21 * t + p1;
}

double dis(Point p1, Point p2){
  return (p1 - p2).abs();
}

double getdis(Segment s, Point p){
  if(dot(s.p2 - s.p1, p - s.p1) < 0) return dis(s.p1, p);
  if(dot(s.p1 - s.p2, p - s.p2) < 0) return dis(s.p2, p);
  return dis(project(p, s.p1, s.p2), p);
}

string ccw(Point p0, Point p1, Point p2){
  Vector v01 = Vector(p1.x - p0.x, p1.y - p0.y);
  Vector v02 = Vector(p2.x - p0.x, p2.y - p0.y);
  if(equals(cross(v01, v02), 0)){
    if(dot(v01, v02) < 0) return "ONLINE_BACK";
    else if(equals(v01.abs(), v02.abs()) == true || v01.abs() > v02.abs()) return "ON_SEGMENT";
    else return "ONLINE_FRONT";
  }
  else if(cross(v01, v02) > 0) return "COUNTER_CLOCKWISE";
  else return "CLOCKWISE";
}

bool intersect(Segment s1, Segment s2){
  if(ccw(s1.p1, s1.p2, s2.p2) == "ON_SEGMENT" || ccw(s1.p1, s1.p2, s2.p1) == "ON_SEGMENT") return true;
  if(ccw(s2.p1, s2.p2, s1.p2) == "ON_SEGMENT" || ccw(s2.p1, s2.p2, s1.p1) == "ON_SEGMENT") return true;
  if(ccw(s1.p1, s1.p2, s2.p1) != ccw(s1.p1, s1.p2, s2.p2)){
    if(ccw(s1.p1, s2.p1, s2.p2) != ccw(s1.p2, s2.p1, s2.p2)) return true;
  }
  return false;
}

Point getcrosspoint(Segment s1, Segment s2){
  Vector base = s2.p2 - s2.p1;
  Vector hypo1 = s1.p1 - s2.p1;
  Vector hypo2 = s1.p2 - s2.p2;
  double d1, d2;
  d1 = abs(cross(base, hypo1)) / base.abs();
  d2 = abs(cross(base, hypo2)) / base.abs();
  return s1.p1 + (s1.p2 - s1.p1) * (d1 / (d1 + d2));
}

void solve(){
  int q; cin >> q;
  vector<Point> ans(q);
  for(int i = 0; i < q; i++){
    double x[4], y[4];
    Point p[4];
    for(int i = 0; i < 4; i++){
      cin >> x[i] >> y[i];
      p[i] = Point(x[i], y[i]);
    }
    Segment s01 = Segment(p[0], p[1]);
    Segment s23 = Segment(p[2], p[3]);
    ans[i] = getcrosspoint(s01, s23);
  }
  for(int i = 0; i < q; i++){
    cout << fixed << setprecision(10) << ans[i].x << " " << ans[i].y << endl;
  }
  return;
}

int main(){
  solve();
  return 0;
}



Measured memory_bytes: 3304