//geometric-2D library
//--------------------------------------------------------------//
#include<complex>
#include<bits/stdc++.h>
#include<cmath>
#include<iostream>
#define eps 1e-9
using namespace std;
typedef complex<double> point;
typedef pair<point, point> line;

double dis(point a, point b);
double dot(point a, point b);
double cross(point a, point b);
int    ccw(point a, point b, point c);
double line_to_point_dis(line l, point p);
double seg_to_point_dis(line l, point p);
double seg_to_seg_dis(line a, line b);
bool   is_cross(line a, line b);
point  cross_point(line a, line b);
pair<point, point> norm(point p);


  //b??????a??????????????????
double dis(point a, point b){
  return abs(a - b);
}

//??????
double dot(point a, point b){
  return a.real()*b.real() + a.imag()*b.imag();
}

//??????
double cross(point a, point b){
  return imag(conj(a) * b);
}

//counter clock wise
int ccw(point a, point b, point c){
  if(cross(b - a, c - a) >  eps)return  1;//??????ab????????´
  if(cross(b - a, c - a) < -eps)return -1;//??????ab????????´
  if(dot(b - a, c - a) < -eps)return 2;//??´???ab??????a???????????????
  if(abs(b - a) + eps < abs(c - a))return -2;//??´???ab??????b???????????????
  return 0;//??´???ab???
}

double line_to_point_dis(line l, point p){
  return abs(cross(p - l.first, l.second - l.first))/
    abs(l.second - l.first);
}

double seg_to_point_dis(line l, point p){
  point a = l.first, b = l.second, c = p;
  if(dot(b - a, c - a) < eps)return abs(c - a);
  if(dot(a - b, c - b) < eps)return abs(c - b);
  return line_to_point_dis(l, p);
}

double seg_to_seg_dis(line a, line b){
  double res = seg_to_point_dis(a, b.first);
  res = min(res, seg_to_point_dis(a, b.second));
  res = min(res, seg_to_point_dis(b, a.first));
  res = min(res, seg_to_point_dis(b, a.second));
  return res;
}

bool is_cross(line a, line b){
  if(ccw(a.first, a.second, b.first) *
     ccw(a.first, a.second, b.second) <= 0 &&
     ccw(b.first, b.second, a.first) *
     ccw(b.first, b.second, a.second) <= 0){
    return true;
  }
  return false;
}

point cross_point(line a, line b){
  double d1 = cross(b.second - b.first,
                    b.first - a.first);
  double d2 = cross(b.second - b.first,
                    a.second - a.first);
  return a.first + (a.second - a.first) * d1/d2;
}

pair<point, point> norm(point p){
  return pair<point, point>(p*point(0, 1),
                            p*point(0, -1));
}

//point a, b, point c, d
point seg_to_seg_cross_point(line a, line c){
  if(not is_cross(a, c)) return point(1e9, 1e9);
  double xa = a.first.real(),  ya = a.first.imag();
  double xb = a.second.real(), yb = a.second.imag();
  double xc = c.first.real(),  yc = c.first.imag();
  double xd = c.second.real(), yd = c.second.imag();
  double s  = (ya - yc)*(xb - xa) + (yb - ya)*(xc - xa);
  double t  = (xb - xa)*(yd - yc) - (xd - xc)*(yb - ya);
  if(abs(t) < eps) return point(1e9, 1e9);
  return c.first + s*(c.second - c.first)/t;
}


int main(){
  int q;
  std::cin >> q;
  for (int i = 0; i < q; i++) {
    vector<point> vp(4);
    for (int i = 0; i < 4; i++) {
      double x, y;
      std::cin >> x >> y;
      vp[i] = point(x, y);
    }
    point ans = seg_to_seg_cross_point(line(vp[0], vp[1]), line(vp[2], vp[3]));
    std::cout << fixed << setprecision(12) << ans.real() << " "<< ans.imag() << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3312