#include <stdio.h>
#include <math.h>


int main() {
    int x, y, x0, y0, x1, y1, x2, y2, x3, y3;
    int q;
    double t, num, denom, vx, vy;
    int judge;

    scanf("%d", &q);
    
    while (q--) {
        scanf("%d %d %d %d %d %d %d %d",
              &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
        vx = x1 - x0;
        vy = y1 - y0;
        num = (y3-y2)*(x2-x0)-(x3-x2)*(y2-y0);
        denom = (x1-x0)*(y3-y2) - (y1-y0)*(x3-x2);
        t = num / denom;

        printf("%.10f %.10f\n", vx * t + x0, vy * t + y0);
    }

    return 0;
}