// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

typedef db T;
struct P{
    T x,y;
    P(){} P(T x,T y):x(x),y(y){}
    void read(){scanf("%lf%lf",&x,&y);}
    P operator - (const P&b) const {return P(x-b.x,y-b.y);}
    P operator + (const P&b) const {return P(x+b.x,y+b.y);}
    T operator * (const P&b) const {return x*b.x+y*b.y;}
    P operator * (const T&k) const {return P(x*k,y*k);}
    T operator ^ (const P&b) const {return x*b.y-y*b.x;}
};

struct L{
    P s,t;
    L(){} L(P s,P t):s(s),t(t){}
    void read(){s.read();t.read();}
};

P insLL(L a,L b){ // line x line
    P s = a.s - b.s , v = a.t - a.s , w = b.t - b.s;
    db k1 = s ^ w , k2 = w ^ v;
    return a.s + v * (k1 / k2);
}

int main(){
    int Q;scanf("%d",&Q);
    rep(i,0,Q){
        L a,b;a.read();b.read();
        P p=insLL(a,b);
        printf("%.10f %.10f\n",p.x,p.y);
    }
    return 0;
}