#include <bits/stdc++.h>
using namespace std;

const double eps = 1e-10;
bool dcmp(double d, double d2 = 0) { return abs(d - d2) < eps; }

struct vec {
  double x, y;
  vec(double x, double y) : x(x), y(y) {}
  vec() : x(0), y(0) {}
  const bool operator==(const vec &v) const {
    return dcmp(x, v.x) && dcmp(y, v.y);
  }
  const bool operator!=(const vec &v) const { return !(*this == v); }
  const vec operator+(const vec &v) const { return vec(x + v.x, y + v.y); }
  const vec operator-() const { return vec(-x, -y); }
  const vec operator-(const vec &v) const { return *this + (-v); }
  const vec operator*(const double d) const { return vec(x * d, y * d); }
  const vec operator/(const double d) const { return *this * (1 / d); }
  const vec unit() const { return *this / len(); };
  const double len() const { return sqrt(x * x + y * y); }
  const double dot(const vec &v) const { return x * v.x + y * v.y; }
  const double cross(const vec &v) const { return x * v.y - y * v.x; }
  const bool parallel(const vec &v) const { return dcmp(cross(v)); }
  const bool perpendicular(const vec &v) const { return dcmp(dot(v)); }
};

typedef vec point;

template <class T> struct optional {
  bool has;
  T val;
  optional() : has(false) {}
  optional(T t) : has(true), val(t) {}
};

struct line {
  double a, b, c;
  line(point p1, point p2) {
    a = p2.y - p1.y;
    b = p1.x - p2.x;
    c = p1.x * p2.y - p2.x * p1.y;
  }
  optional<point> intersect(line l) {
    if (dcmp(a * l.b, b * l.a))
      return optional<point>();
    return point((c * l.b - b * l.c) / (a * l.b - b * l.a),
                 -(c * l.a - a * l.c) / (a * l.b - b * l.a));
  }
};

struct segment {
  point p1, p2;
  point intersect(segment s) {}
};

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    point p0, p1, p2, p3;
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    line l0(p0, p1);
    line l1(p2, p3);
    point p = l0.intersect(l1).val;
    printf("%.9lf %.9lf\n", p.x, p.y);
  }
}
