#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, b, e) for (intmax_t i = (b), i##_limit = (e); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class Container>
struct reverse_t {
    Container &c;
    reverse_t(Container &c) : c(c) {}
    auto begin() { return c.rbegin(); }
    auto end() { return c.rend(); }
};

template <class Container>
auto reversed(Container &c) {
    return reverse_t<Container>(c);
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

// Geometry {{{
const long double EPS = 1e-10;
const long double PI = acos(-1);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

struct Real {
    long double x;

    Real(long double x = 0) : x(x) {}
    Real(const Real& rhs) { x = rhs.x; }

    Real operator+(const Real& rhs) const { return Real(x + rhs.x); }
    Real& operator+=(const Real& rhs) { return x += rhs.x, *this; }
    Real operator-(const Real& rhs) const { return Real(x - rhs.x); }
    Real& operator-=(const Real& rhs) { return x -= rhs.x, *this; }
    Real operator*(const Real& rhs) const { return Real(x * rhs.x); }
    Real& operator*=(const Real& rhs) { return x *= rhs.x, *this; }
    Real operator/(const Real& rhs) const { return Real(x / rhs.x); }
    Real& operator/=(const Real& rhs) { return x /= rhs.x, *this; }
    Real operator-() const { return Real(-x); }
    Real& operator++() { return ++x, *this; }
    Real& operator--() { return --x, *this; }
    Real operator++(int) { Real tmp(x); return ++x, tmp; }
    Real operator--(int) { Real tmp(x); return --x, tmp; }
    bool operator==(const Real& rhs) const { return fabs(x - rhs.x) < EPS; }
    bool operator!=(const Real& rhs) const { return !(*this == rhs); }
    bool operator<(const Real& rhs) const { return (*this == rhs) ? false : x < rhs.x; }
    bool operator>(const Real& rhs) const { return (*this == rhs) ? false : x > rhs.x; }
    bool operator<=(const Real& rhs) const { return (*this == rhs) ? true : x < rhs.x; }
    bool operator>=(const Real& rhs) const { return (*this == rhs) ? true : x > rhs.x; }

    friend istream& operator>>(istream& is, Real& rhs) {
        is >> rhs.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const Real& rhs) {
        os << rhs.x;
        return os;
    }

    friend Real pow(const Real& n, const Real& p) { return pow(n.x, p.x); }
    friend Real pow(Real n, intmax_t p) {
        Real ret = 1;
        for (; p > 0; p >>= 1) {
            if (p & 1) ret *= n;
            n *= n;
        }
        return ret;
    }
    friend Real abs(const Real& rhs) { return abs(rhs.x); }
    friend Real sin(const Real& rhs) { return sin(rhs.x); }
    friend Real cos(const Real& rhs) { return cos(rhs.x); }
    friend Real tan(const Real& rhs) { return tan(rhs.x); }
    friend Real asin(const Real& rhs) { return asin(rhs.x); }
    friend Real acos(const Real& rhs) { return acos(rhs.x); }
    friend Real atan(const Real& rhs) { return atan(rhs.x); }
    friend Real atan2(const Real& lhs, const Real& rhs) { return atan2(lhs.x, rhs.x); }
    friend Real sqrt(const Real& rhs) { return sqrt(rhs.x); }
    friend Real ceil(const Real& rhs) { return ceil(rhs.x); }
    friend Real floor(const Real& rhs) { return floor(rhs.x); }
    friend Real round(const Real& rhs) { return round(rhs.x); }
};

using real_t = Real;

struct Point {
    real_t x, y;

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

    Point operator+(const Point& rhs) const { return Point(x + rhs.x, y + rhs.y); }
    Point operator-(const Point& rhs) const { return Point(x - rhs.x, y - rhs.y); }
    Point operator*(const real_t& rhs) const { return Point(x * rhs, y * rhs); }
    Point operator/(const real_t& rhs) const { return Point(x / rhs, y / rhs); }
    Point operator-() const { return Point(-x, -y); }
    bool operator==(const Point& rhs) const { return x == rhs.x && y == rhs.y; }
    bool operator!=(const Point& rhs) const { return !(*this == rhs); }
    bool operator<(const Point& rhs) const { return (x == rhs.x) ? y < rhs.y : x < rhs.x; }
    bool operator>(const Point& rhs) const { return (x == rhs.x) ? y > rhs.y : x > rhs.x; }
    bool operator<=(const Point& rhs) const { return (*this == rhs) ? true : *this < rhs; }
    bool operator>=(const Point& rhs) const { return (*this == rhs) ? true : *this > rhs; }

    friend istream& operator>>(istream& is, Point& rhs) {
        is >> rhs.x >> rhs.y;
        return is;
    }
    friend ostream& operator<<(ostream& os, const Point& rhs) {
        os << rhs.x << ' ' << rhs.y;
        return os;
    }
};

using Vector = Point;

real_t norm(const Vector& a) { return a.x * a.x + a.y * a.y; }
real_t len(const Vector& a) { return sqrt(norm(a)); }
real_t dot(const Vector& a, const Vector& b) {
    return a.x * b.x + a.y * b.y;
}
real_t cross(const Vector& a, const Vector& b) {
    return a.x * b.y - a.y * b.x;
}

struct Segment {
    Point p1, p2;

    Segment(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}

    bool operator==(const Segment& rhs) const { return p1 == rhs.p1 && p2 == rhs.p2; }
    bool operator!=(const Segment& rhs) const { return !(*this == rhs); }

    friend istream& operator>>(istream& is, Segment& rhs) {
        is >> rhs.p1 >> rhs.p2;
        return is;
    }
    friend ostream& operator<<(ostream& os, const Segment& rhs) {
        os << rhs.p1 << ' ' << rhs.p2;
        return os;
    }
};

using Line = Segment;

real_t len(const Segment& s) { return len(s.p1 - s.p2); }

bool isParallel(const Vector& a, const Vector& b) {
    return cross(a, b) == 0.0;
}
bool isParallel(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    return isParallel(a1 - a2, b1 - b2);
}
bool isParallel(const Segment& s1, const Segment& s2) {
    return isParallel(s1.p1, s1.p2, s2.p1, s2.p2);
}

bool isOrthogonal(const Vector& a, const Vector& b) {
    return dot(a, b) == 0.0;
}
bool isOrthogonal(const Point& a1, const Point& a2, const Point& b1, const Point& b2) {
    return isOrthogonal(a1 - a2, b1 - b2);
}
bool isOrthogonal(const Segment& s1, const Segment& s2) {
    return isOrthogonal(s1.p1, s1.p2, s2.p1, s2.p2);
}

Point project(const Segment& s, const Point& p) {
    const Vector base = s.p2 - s.p1;
    const Vector hypo = p - s.p1;
    const real_t r = dot(hypo, base) / norm(base);
    return s.p1 + base * r;
}

int ccw(const Point& p0, const Point& p1, const Point& p2) {
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if (cross(a, b) > 0.0) return COUNTER_CLOCKWISE;
    if (cross(a, b) < 0.0) return CLOCKWISE;
    if (dot(a, b) < 0) return ONLINE_BACK;
    if (norm(a) < norm(b)) return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool intersect(const Point& p1, const Point& p2, const Point& p3, const Point& p4) {
    return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0;
}

bool intersect(const Segment& s1, const Segment& s2) {
    return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

Point reflect(const Segment& s, const Point& p) {
    return p + (project(s, p) - p) * 2.0;
}

real_t getDistancePP(const Point& p1, const Point& p2) {
    return len(p2 - p1);
}

real_t getDistanceLP(const Line& l, const Point& p) {
    return abs(cross(l.p2 - l.p1, p - l.p1) / len(l.p2 - l.p1));
}

real_t getDistanceSP(const Segment& s, const Point& p) {
    if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return getDistancePP(p, s.p1);
    if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return getDistancePP(p, s.p2);
    return getDistanceLP(s, p);
}

real_t getDistanceSS(const Segment& s1, const Segment& s2) {
    if (intersect(s1, s2)) return 0.0;
    const real_t opt1 = getDistanceSP(s1, s2.p1);
    const real_t opt2 = getDistanceSP(s1, s2.p2);
    const real_t opt3 = getDistanceSP(s2, s1.p1);
    const real_t opt4 = getDistanceSP(s2, s1.p2);
    return min({opt1, opt2, opt3, opt4});
}

Point getCrossPoint(const Segment& s1, const Segment& s2) {
    Vector base = s2.p2 - s2.p1;
    const real_t d1 = abs(cross(base, s1.p1 - s2.p1));
    const real_t d2 = abs(cross(base, s1.p2 - s2.p1));
    const real_t t = d1 / (d1 + d2);
    return s1.p1 + (s1.p2 - s1.p1) * t;
}
// }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    var(size_t, Q);

    while (Q--) {
        var(Segment, s1, s2);
        output(getCrossPoint(s1, s2));
    }

    return 0;
}



Measured memory_bytes: 3316