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

#define EPS 1e-10

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		double x1, y1, x2, y2, x3, y3, x4, y4;
		double dn, nm, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4 );

		dn = ( x2 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y1 );
		nm = ( x3 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y3 - y1 );

		if ( fabs( dn ) < EPS ) {
			double h1 = x1 == x2 ? ( y3 - y1 ) / ( y2 - y1 ) : ( x3 - x1 ) / ( x2 - x1 );
			double h2 = x1 == x2 ? ( y4 - y1 ) / ( y2 - y1 ) : ( x4 - x1 ) / ( x2 - x1 );

			if ( ( h1 < h2 ? h1 : h2 ) < 0.0 && fabs( h1 < h2 ? h2 : h1 ) < EPS ) {
				x = x1;
				y = y1;
			} else if ( fabs( ( h1 < h2 ? h1 : h2 ) - 1.0 ) < EPS && 1.0 < ( h1 < h2 ? h2 : h1 ) ) {
				x = x2;
				y = y2;
			}
		} else {
			x = x1 + nm / dn * ( x2 - x1 );
			y = y1 + nm / dn * ( y2 - y1 );
		}

		printf( "%.8f %.8f\n", x, y );
	}

	return 0;
}