#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

const double eps = 1e-10;

class Vector
{
public:
  double x;
  double y;

  Vector(){}
  Vector( double x, double y ) : x(x), y(y) {}

  Vector operator + ( const Vector v ) { return Vector( x + v.x, y + v.y ); }
  Vector operator - ( const Vector v ) { return Vector( x - v.x, y - v.y ); }
  Vector operator * ( const double k ) { return Vector( x * k, y * k ); }
  Vector operator / ( const double k ) { return Vector( x / k, y / k ); }
  bool operator < ( const Vector &v ) const { return x * x + y * y < v.x * v.x + v.y * v.y; }

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

  static double dot( Vector v1, Vector v2 ) { return v1.x * v2.x + v1.y * v2.y; }
  static double cross( Vector v1, Vector v2 ) { return v1.x * v2.y - v1.y * v2.x; }
  
  void print() { cout << fixed << setprecision(10) << x << " " << y << endl; }
};

class CrossPoint
{
public:
  Vector p0, p1, p2, p3;
  CrossPoint(){}
  CrossPoint( Vector p0, Vector p1, Vector p2, Vector p3 ) : p0(p0), p1(p1), p2(p2), p3(p3) {}
  int solve();
};

int CrossPoint::solve()
{
  Vector a = p1 - p0;
  Vector b = p3 - p2;
  Vector p = p2 - p0;

  Vector cp = p0 + a * Vector::cross( b, p ) / Vector::cross( b, a );
  cp.print();
  
  return 0;
}

int main()
{
  int q;
  cin >> q;
  
  for ( auto i = 0; i < q; ++i )
    {
      double xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
      cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;

      CrossPoint cp(Vector(xp0, yp0), Vector(xp1, yp1), Vector(xp2, yp2), Vector(xp3, yp3));
      cp.solve();
    }

  return 0;
}