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

#define swap( x, y ) do { double tmp; tmp = x; x = y; y = tmp; } while ( 0 )
#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 ) {
			if ( x1 == x2 ) {
				if ( y2 < y1 )
					swap( y1, y2 );
				if ( y4 < y3 )
					swap( y3, y4 );

				if ( y4 < y1 || y2 < y3 )
					return 3;
				else if ( y4 == y1 || y2 == y3 ) {
					*x = x1
					*y = y4 == y1 ? y1 : y2;
					return 4;
				} else
					return 5;
			} else {
				if ( x2 < x1 ) {
					swap( x1, x2 );
					swap( y1, y2 );
				}
				if ( x4 < x3 )
					swap( x3, x4 );

				if ( x4 < x1 || x2 < x3 )
					return 3;
				else if ( x4 == x1 || x2 == x3 ) {
					*x = x4 == x1 ? x1 : x2;
					*y = x4 == x1 ? y1 : y2;
					return 4;
				} 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;
}