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

#define EPS 1e-10

int rel_s_s( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double *x, double *y ) {
	double dn = ( x2 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y1 );
	double nm = ( x3 - x1 ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y3 - y1 );

	if ( fabs( dn ) < EPS )
		if ( fabs( nm ) < 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;
				return 4;
			} else if ( fabs( ( h1 < h2 ? h1 : h2 ) - 1.0 ) < EPS && 1.0 < ( h1 < h2 ? h2 : h1 ) ) {
				*x = x2;
				*y = y2;
				return 4;
			} else if ( h1 < 0.0 && h2 < 0.0 || 1.0 < h1 && 1.0 < h2 )
				return 3;
			else
				return 5;
		} else
			return 2;
	else
		if ( fabs( nm / dn - 0.5 ) < 0.5 + EPS && fabs( ( ( x3 - x1 ) * ( y2 - y1 ) - ( x2 - x1 ) * ( y3 - y1 ) ) / dn - 0.5 ) < 0.5 + EPS ) {
			*x = x1 + nm / dn * ( x2 - x1 );
			*y = y1 + nm / dn * ( y2 - y1 );

			if ( fabs( ( x2 - x1 ) * ( x4 - x3 ) + ( y2 - y1 ) * ( y4 - y3 ) ) < EPS )
				return 1;
			else
				return 0;
		} else
			return 6;
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		double x0, y0, x1, y1, x2, y2, x3, y3, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		rel_s_s( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y );
		printf( "%.8f %.8f\n", x, y );
	}

	return 0;
}