#include <stdio.h>

int main( void ) {
	int q;

	scanf( "%d", &q );

	while ( q-- ) {
		double x0, y0, x1, y1, x2, y2, x3, y3;
		double a, b, c, d, x, y;

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

		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;
		}

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

	return 0;
}