#include <stdio.h>

int intsec_line( double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double *x, double *y ) {
	double a, b, c, d;

	if ( x0 != x1 ) {
		a = ( y0 - y1 ) / ( x0 - x1 );
		b = ( x0 * y1 - x1 * y0 ) / ( x0 - x1 );
	}

	if ( x2 != x3 ) {
		c = ( y2 - y3 ) / ( x2 - x3 );
		d = ( x2 * y3 - x3 * y2 ) / ( x2 - x3 );
	}

	if ( x0 == x1 ) {
		*x = x0;
		if ( x2 == x3 )
			*y = y0 == y2 || y0 == y3 ? y0 : y1;
		else
			*y = c * *x + d;
	} else {
		if ( x2 == x3 )
			*x = x2;
		else if ( a == c )
			*x = x0 == x2 || x0 == x3 ? x0 : x1;
		else
			*x = ( -b + d ) / ( a - c );
		*y = a * *x + b;
	}

	return 0;
}


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 );
		intsec_line( x0, y0, x1, y1, x2, y2, x3, y3, &x, &y );

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

	return 0;
}