#include<stdio.h>
int main(){
    int n,ax,ay,bx,by,cx,cy,dx,dy;
    double x,y,t;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
        t=(double)((cx-ax)*(dy-cy)-(cy-ay)*(dx-cx))/(double)((bx-ax)*(dy-cy)-(by-ay)*(dx-cx));
        x=ax+t*(bx-ax);
        y=ay+t*(by-ay);
        printf("%.10f %.10f\n",x,y);
    }
    return 0;
}