#include <stdio.h>

void closs(double a1[2], double b1[2],
            double a2[2], double b2[2],double ans[2]);

int main(void)
{
    int i, n;
    double p1[2], p2[2], p3[2], p4[2], ans[2];
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%lf%lf%lf%lf %lf%lf%lf%lf", 
            &p1[0], &p1[1], &p2[0], &p2[1], &p3[0], &p3[1], &p4[0], &p4[1]);
        closs(p1, p2, p3, p4, ans);
        printf("%.9lf %.9lf\n", ans[0], ans[1]);
    }
    return 0;
}

void closs(double a1[2], double b1[2],
            double a2[2], double b2[2],double ans[2]) 
{
    //a1-b1 & a2-b2 の交点
    double s1, s2;

    s1 = ((b2[0] - a2[0])*(a1[1] - a2[1]) 
            - ((b2[1] - a2[1])*(a1[0] - a2[0]))) / 2;

    s2 = ((b2[0] - a2[0])*(a2[1] - b1[1]) 
            - ((b2[1] - a2[1])*(a2[0] - b1[0]))) / 2;

    ans[0] = a1[0] + (b1[0] - a1[0])*s1/(s1 + s2);
    ans[1] = a1[1] + (b1[1] - a1[1])*s1/(s1 + s2);
}