For given two segments s1 and s2, print the coordinate of the cross point of them.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
* The given segments have a cross point and are not in parallel.

Input

The entire input looks like:


q (the number of queries)
1st query
2nd query
...
qth query


Each query consists of integer coordinates of end points of s1 and s2 in the following format:


xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3


Output

For each query, print the coordinate of the cross point. The output values should be in a decimal fraction with an error less than 0.00000001.

Example

Input

3
0 0 2 0 1 1 1 -1
0 0 1 1 0 1 1 0
0 0 1 1 1 0 0 1


Output

1.0000000000 0.0000000000
0.5000000000 0.5000000000
0.5000000000 0.5000000000

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
def dot(a, b):
	return a.real * b.real + a.imag * b.imag

def cross(a, b):
	return a.real * b.imag - a.imag * b.real

def cross_point(p0, p1, p2, p3):
	base = p3 - p2
	d1 = abs(cross(base, p0 - p2))
	d2 = abs(cross(base, p1 - p2))
	t = d1 / (d1 + d2)
	ans = p0 + (p1 - p0) * t
	return (ans.real, ans.imag)
n = int(input())
for i in range(n):
	(x0, y0, x1, y1, x2, y2, x3, y3) = map(int, input().split())
	p0 = complex(x0, y0)
	p1 = complex(x1, y1)
	p2 = complex(x2, y2)
	p3 = complex(x3, y3)
	print(*cross_point(p0, p1, p2, p3))


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inp():
	return int(input())

def inpl():
	return list(map(int, input().split()))

def inpl_str():
	return list(input().split())

def sgn(a):
	if a < -eps:
		return -1
	if a > eps:
		return 1
	return 0

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y
		pass

	def tolist(self):
		return [self.x, self.y]

	def __add__(self, p):
		return Point(self.x + p.x, self.y + p.y)

	def __iadd__(self, p):
		return self + p

	def __sub__(self, p):
		return Point(self.x - p.x, self.y - p.y)

	def __isub__(self, p):
		return self - p

	def __truediv__(self, n):
		return Point(self.x / n, self.y / n)

	def __itruediv__(self, n):
		return self / n

	def __mul__(self, n):
		return Point(self.x * n, self.y * n)

	def __imul__(self, n):
		return self * n

	def __lt__(self, other):
		tmp = sgn(self.x - other.x)
		if tmp != 0:
			return tmp < 0
		else:
			return sgn(self.y - other.y) < 0

	def __eq__(self, other):
		return sgn(self.x - other.x) == 0 and sgn(self.y - other.y) == 0

	def abs(self):
		return math.sqrt(self.x ** 2 + self.y ** 2)

	def dot(self, p):
		return self.x * p.x + self.y * p.y

	def det(self, p):
		return self.x * p.y - self.y * p.x

	def arg(self, p):
		return math.atan2(y, x)

def iSP(a, b, c):
	tmp = sgn((b - a).det(c - a))
	if tmp > 0:
		return 1
	elif tmp < 0:
		return -1
	else:
		if sgn((b - a).dot(c - a)) < 0:
			return -2
		if sgn((a - b).dot(c - b)) < 0:
			return 2
		return 0

def isToleranceLine(a, b, c, d):
	if sgn((b - a).det(c - d)) != 0:
		return 1
	elif sgn((b - a).det(c - a)) != 0:
		return 0
	else:
		return -1

def isToleranceSegline(a, b, c, d):
	return sgn(iSP(a, b, c) * iSP(a, b, d)) <= 0 and sgn(iSP(c, d, a) * iSP(c, d, b)) <= 0

def Intersection(a, b, c, d):
	tmp1 = (b - a) * (c - a).det(d - c)
	tmp2 = (b - a).det(d - c)
	return a + tmp1 / tmp2

def DistanceLineToPoint(a, b, c):
	return abs((c - a).det(b - a) / (b - a).abs())

def DistanceSeglineToPoint(a, b, c):
	if sgn((b - a).dot(c - a)) < 0:
		return (c - a).abs()
	if sgn((a - b).dot(c - b)) < 0:
		return (c - b).abs()
	return DistanceLineToPoint(a, b, c)

def Vfoot(a, b, c):
	d = c + Point((b - a).y, -(b - a).x)
	return Intersection(a, b, c, d)

def PolygonArea(Plist):
	Plist = ConvexHull(Plist)
	L = len(Plist)
	S = 0
	for i in range(L):
		tmpS = Plist[i - 1].det(Plist[i]) / 2
		S += tmpS
	return S

def PolygonG(Plist):
	Plist = ConvexHull(Plist)
	L = len(Plist)
	S = 0
	G = Point(0, 0)
	for i in range(L):
		tmpS = Plist[i - 1].det(Plist[i]) / 2
		S += tmpS
		G += (Plist[i - 1] + Plist[i]) / 3 * tmpS
	return G / S

def ConvexHull(Plist):
	Plist.sort()
	L = len(Plist)
	qu = deque([])
	quL = 0
	for p in Plist:
		while quL >= 2 and iSP(qu[quL - 2], qu[quL - 1], p) == 1:
			qu.pop()
			quL -= 1
		qu.append(p)
		quL += 1
	qd = deque([])
	qdL = 0
	for p in Plist:
		while qdL >= 2 and iSP(qd[qdL - 2], qd[qdL - 1], p) == -1:
			qd.pop()
			qdL -= 1
		qd.append(p)
		qdL += 1
	qd.pop()
	qu.popleft()
	hidari = list(qd) + list(reversed(qu))
	return hidari
N = int(input())
for _ in range(N):
	(x0, y0, x1, y1, x2, y2, x3, y3) = inpl()
	p0 = Point(x0, y0)
	p1 = Point(x1, y1)
	p2 = Point(x2, y2)
	p3 = Point(x3, y3)
	print(*Intersection(p0, p1, p2, p3).tolist())


from sys import stdin

class Vector:

	def __init__(self, x=None, y=None):
		self.x = x
		self.y = y

	def __add__(self, other):
		return Vector(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Vector(self.x - other.x, self.y - other.y)

	def __mul__(self, k):
		return Vector(self.x * k, self.y * k)

	def __gt__(self, other):
		return self.x > other.x and self.y > other.yb

	def __lt__(self, other):
		return self.x < other.x and self.y < other.yb

	def __eq__(self, other):
		return self.x == other.x and self.y == other.y

	def dot(self, other):
		return self.x * other.x + self.y * other.y

	def cross(self, other):
		return self.x * other.y - self.y * other.x

	def norm(self):
		return self.x * self.x + self.y * self.y

	def abs(self):
		return math.sqrt(self.norm())

class Point(Vector):

	def __init__(self, *args, **kargs):
		return super().__init__(*args, **kargs)

class Segment:

	def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
		self.p1 = p1
		self.p2 = p2

def get_cross_point(s1, s2):
	base = s2.p2 - s2.p1
	hypo1 = s1.p1 - s2.p1
	hypo2 = s1.p2 - s2.p1
	d1 = abs(base.cross(hypo1))
	d2 = abs(base.cross(hypo2))
	t = d1 / (d1 + d2)
	return s1.p1 + (s1.p2 - s1.p1) * t

def read_and_print_results(n):
	for _ in range(n):
		line = stdin.readline().strip().split()
		p0 = Vector(int(line[0]), int(line[1]))
		p1 = Vector(int(line[2]), int(line[3]))
		p2 = Vector(int(line[4]), int(line[5]))
		p3 = Vector(int(line[6]), int(line[7]))
		s1 = Segment(p0, p1)
		s2 = Segment(p2, p3)
		p = get_cross_point(s1, s2)
		print('{0:0.10f} {1:0.10f}'.format(p.x, p.y))
n = int(input())
read_and_print_results(n)


import math
from typing import Union

class Point(object):
	__slots__ = ['x', 'y']

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __add__(self, other):
		return Point(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Point(self.x - other.x, self.y - other.y)

	def __mul__(self, other: Union[int, float]):
		return Point(self.x * other, self.y * other)

	def __repr__(self):
		return f'({self.x},{self.y})'

class Vector(Point):
	__slots__ = ['x', 'y', 'pt1', 'pt2']

	def __init__(self, pt1: Point, pt2: Point):
		from_pt1_to_pt2 = pt2 - pt1
		super().__init__(from_pt1_to_pt2.x, from_pt1_to_pt2.y)
		self.pt1 = pt1
		self.pt2 = pt2

	def dot(self, other):
		return self.x * other.x + self.y * other.y

	def cross(self, other):
		return self.x * other.y - self.y * other.x

	def norm(self):
		return pow(self.x, 2) + pow(self.y, 2)

	def abs(self):
		return math.sqrt(self.norm())

	def __repr__(self):
		return f'{self.pt1},{self.pt2}'

class Segment(Vector):
	__slots__ = ['x', 'y', 'pt1', 'pt2']

	def __init__(self, pt1: Point, pt2: Point):
		super().__init__(pt1, pt2)

	def projection(self, pt: Point) -> Point:
		t = self.dot(Vector(self.pt1, pt)) / pow(self.abs(), 2)
		return Point(self.pt1.x + t * self.x, self.pt1.y + t * self.y)

	def reflection(self, pt: Point) -> Point:
		return self.projection(pt) * 2 - pt

	def is_intersected_with(self, other) -> bool:
		if self.point_geometry(other.pt1) * self.point_geometry(other.pt2) <= 0 and other.point_geometry(self.pt1) * other.point_geometry(self.pt2) <= 0:
			return True
		else:
			return False

	def point_geometry(self, pt: Point) -> int:
		vec_pt1_to_pt = Vector(self.pt1, pt)
		cross = self.cross(vec_pt1_to_pt)
		if cross > 0:
			return -1
		elif cross < 0:
			return 1
		else:
			dot = self.dot(vec_pt1_to_pt)
			if dot < 0:
				return -2
			elif self.abs() < vec_pt1_to_pt.abs():
				return 2
			else:
				return 0

	def cross_point(self, other) -> Point:
		d1 = abs(self.cross(Vector(self.pt1, other.pt1)))
		d2 = abs(self.cross(Vector(self.pt1, other.pt2)))
		t = d1 / (d1 + d2)
		return other.pt1 + other * t

	def __repr__(self):
		return f'{self.pt1},{self.pt2}'

def main():
	num_query = int(input())
	for i in range(num_query):
		(p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y) = map(int, input().split())
		seg_1 = Segment(Point(p0_x, p0_y), Point(p1_x, p1_y))
		seg_2 = Segment(Point(p2_x, p2_y), Point(p3_x, p3_y))
		pt = seg_1.cross_point(seg_2)
		print(f'{pt.x:.10f} {pt.y:.10f}')
	return
main()


EPS = 1e-10
COUNTER_CLOCKWISE = 1
CLOCKWISE = -1
ONLINE_BACK = 2
ONLINE_FRONT = -2
ON_SEGMENT = 0

class Point:
	global EPS

	def __init__(self, x=0, y=0):
		self.x = x
		self.y = y

	def __add__(a, b):
		s = a.x + b.x
		t = a.y + b.y
		return Point(s, t)

	def __sub__(a, b):
		s = a.x - b.x
		t = a.y - b.y
		return Point(s, t)

	def __mul__(self, a):
		s = a * self.x
		t = a * self.y
		return Point(s, t)

	def __truediv__(self, a):
		s = self.x / a
		t = self.y / a
		return Point(s, t)

	def norm(self):
		return self.x * self.x + self.y * self.y

	def abs(self):
		return self.norm() ** 0.5

	def __eq__(self, other):
		return abs(self.x - other.y) < self.EPS and abs(self.y - other.y) < self.EPS

	def dot(self, b):
		return self.x * b.x + self.y * b.y

	def cross(self, b):
		return self.x * b.y - self.y * b.x

class Segment:

	def __init__(self, p1, p2):
		self.p1 = p1
		self.p2 = p2

def project(s, p):
	base = s.p2 - s.p1
	hypo = p - s.p1
	r = hypo.dot(base) / base.norm()
	return s.p1 + base * r

def reflecton(s, p):
	return p + (project(s, p) - p) * 2

def getDistance(a, b):
	return (a - b).abs()

def getDistanceLP(l, p):
	return abs((l.p2 - l.p1).cross(p - l.p1)) / (l.p2 - l.p1).abs()

def getDistanceSP(s, p):
	if (s.p2 - s.p1).dot(p - s.p1) < 0:
		return (p - s.p1).abs()
	elif (s.p1 - s.p2).dot(p - s.p2) < 0:
		return (p - s.p2).abs()
	return getDistanceLP(s, p)

def getDistanceSS(s1, s2):
	if intersectS(s1, s2):
		return 0
	return min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2), getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))

def ccw(p0, p1, p2):
	a = p1 - p0
	b = p2 - p0
	if a.cross(b) > 0:
		return COUNTER_CLOCKWISE
	elif a.cross(b) < 0:
		return CLOCKWISE
	elif a.dot(b) < 0:
		return ONLINE_BACK
	elif a.abs() < b.abs():
		return ONLINE_FRONT
	else:
		return ON_SEGMENT

def intersect(p1, p2, p3, p4):
	return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0

def intersectS(s1, s2):
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2)

def getCrossPoint(s1, s2):
	base = s2.p2 - s2.p1
	a = s1.p1 - s2.p1
	b = s1.p2 - s2.p1
	d1 = abs(a.cross(base))
	d2 = abs(b.cross(base))
	t = d1 / (d1 + d2)
	return s1.p1 + (s1.p2 - s1.p1) * t
n = int(input())
for i in range(n):
	nums = list(map(int, input().split()))
	s1 = Segment(Point(nums[0], nums[1]), Point(nums[2], nums[3]))
	s2 = Segment(Point(nums[4], nums[5]), Point(nums[6], nums[7]))
	print(getCrossPoint(s1, s2).x, getCrossPoint(s1, s2).y)


from functools import singledispatch
import math
EPS = 1e-10
COUNTER_CLOCKWISE = 1
CLOCKWISE = -1
ONLINE_BACK = 2
ONLINE_FRONT = -2
ON_SEGMENT = 0

class Segment:

	def __init__(self, p1, p2):
		self.p1 = p1
		self.p2 = p2

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __add__(self, point):
		return Point(self.x + point.x, self.y + point.y)

	def __sub__(self, point):
		return Point(self.x - point.x, self.y - point.y)

	def __mul__(self, a):
		return Point(a * self.x, a * self.y)

	def __truediv__(self, a):
		return Point(self.x / a, self.y / a)

	def __abs__(self):
		return math.sqrt(self.norm())

	def norm(self):
		return self.x ** 2 + self.y ** 2

	def __eq__(self, point):
		return abs(self.x - point.x) < EPS and abs(self.y - point.y) < EPS

def dot(a, b):
	return a.x * b.x + a.y * b.y

def cross(a, b):
	return a.x * b.y - a.y * b.x

def isOrthogonal(a, b):
	return dot(a, b) == 0

def isParallel(a, b):
	return cross(a, b) == 0

def project(s, p):
	base = s.p2 - s.p1
	r = dot(p - s.p1, base) / base.norm()
	return s.p1 + base * r

def reflect(s, p):
	return p + (project(s, p) - p) * 2

@singledispatch
def get_distance(a, b):
	return abs(a - b)

def get_distance_lp(l, p):
	return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1))

def get_distance_sp(s, p):
	if dot(s.p2 - s.p1, p - s.p1) < 0:
		return abs(p - s.p1)
	if dot(s.p1 - s.p2, p - s.p2) < 0:
		return abs(p - s.p2)
	return get_distance_lp(s, p)

@get_distance.register(Segment)
def _(s1, s2):
	if intersect(s1, s2):
		return 0
	return min([get_distance_sp(s1, s2.p1), get_distance_sp(s1, s2.p2), get_distance_sp(s2, s1.p1), get_distance_sp(s2, s1.p2)])

def ccw(p0, p1, p2):
	a = p1 - p0
	b = p2 - p0
	if cross(a, b) > EPS:
		return COUNTER_CLOCKWISE
	if cross(a, b) < -EPS:
		return CLOCKWISE
	if dot(a, b) < -EPS:
		return ONLINE_BACK
	if a.norm() < b.norm():
		return ONLINE_FRONT
	return ON_SEGMENT

@singledispatch
def intersect(p1, p2, p3, p4):
	return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0

@intersect.register(Segment)
def _(s1, s2):
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2)

def get_cross_point(s1, s2):
	base = s2.p2 - s2.p1
	d1 = abs(cross(base, s1.p1 - s2.p1))
	d2 = abs(cross(base, s1.p2 - s2.p1))
	t = d1 / (d1 + d2)
	return s1.p1 + (s1.p2 - s1.p1) * t
from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	(x0, y0, x1, y1, x2, y2, x3, y3) = map(int, input().split())
	p0 = Point(x0, y0)
	p1 = Point(x1, y1)
	p2 = Point(x2, y2)
	p3 = Point(x3, y3)
	s1 = Segment(p0, p1)
	s2 = Segment(p2, p3)
	p = get_cross_point(s1, s2)
	print(p.x, p.y)


import sys
from collections import namedtuple

def cross(a, b):
	return a.real * b.imag - a.imag * b.real

def dot(a, b):
	return a.real * b.real + a.imag * b.imag

def get_cross_point(s1, s2):
	base_vector = s2.target - s2.source
	d1 = abs(cross(base_vector, s1.source - s2.source))
	d2 = abs(cross(base_vector, s1.target - s2.source))
	t = d1 / (d1 + d2)
	cross_point = s1.source + (s1.target - s1.source) * t
	print('{real:.10f} {imag:.10f}'.format(real=cross_point.real, imag=cross_point.imag))
	return None

def solve(_segments):
	for segment in _segments:
		segment = tuple(map(int, segment))
		(p0, p1, p2, p3) = (x + y * 1j for (x, y) in zip(segment[::2], segment[1::2]))
		(s1, s2) = (Segment(p0, p1), Segment(p2, p3))
		get_cross_point(s1, s2)
	return None
_input = sys.stdin.readlines()
l_num = int(_input[0])
segments = map(lambda x: x.split(), _input[1:])
Segment = namedtuple('Segment', ('source', 'target'))
solve(segments)


import array
from fractions import Fraction
import math
import os
import sys

def main():
	Q = read_int()
	for _ in range(Q):
		(x0, y0, x1, y1, x2, y2, x3, y3) = read_ints()
		print(*solve(Vec(x0, y0), Vec(x1, y1), Vec(x2, y2), Vec(x3, y3)))

def solve(a, b, c, d):
	p = b - a
	q = c - a
	r = d - a
	k = Fraction(r.cross(q), (r - q).cross(p))
	kp = k * p
	kp += a
	return (float(kp.x), float(kp.y))

class Vec(object):

	def __init__(self, x, y):
		self.x = x
		self.y = y
		super().__init__()

	def __add__(self, other):
		return Vec(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Vec(self.x - other.x, self.y - other.y)

	def __mul__(self, scalar):
		return Vec(self.x * scalar, self.y * scalar)

	def __rmul__(self, scalar):
		return Vec(self.x * scalar, self.y * scalar)

	def __truediv__(self, scalar):
		return Vec(self.x / scalar, self.y / scalar)

	def __iadd__(self, other):
		self.x += other.x
		self.y += other.y
		return self

	def __isub__(self, other):
		self.x -= other.x
		self.y -= other.y
		return self

	def __imul__(self, scalar):
		self.x *= scalar
		self.y *= scalar
		return self

	def __idiv__(self, scalar):
		self.x /= scalar
		self.y /= scalar
		return self

	def __neg__(self):
		return Vec(-self.x, -self.y)

	def dot(self, other):
		return self.x * other.x + self.y * other.y

	def cross(self, other):
		return self.x * other.y - self.y * other.x

	def abs2(self):
		return self.x * self.x + self.y * self.y

	def __abs__(self):
		return math.sqrt(float(self.abs2()))

	def __str__(self):
		return '({}, {})'.format(self.x, self.y)
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


EPS = 0.0001

def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag

def Crosspoint(a, b, c, d):
	if abs(OuterProduct(b - a, d - c)) <= EPS:
		return False
	else:
		u = OuterProduct(c - a, d - a) / OuterProduct(b - a, d - c)
		return (1 - u) * a + u * b
n = int(input())
for _ in range(n):
	pp = list(map(int, input().split()))
	p = [complex(pp[i], pp[i + 1]) for i in range(0, 8, 2)]
	ans = Crosspoint(p[0], p[1], p[2], p[3])
	print(ans.real, ans.imag)


def cross(a: complex, b: complex) -> float:
	return float(a.real * b.imag - a.imag * b.real)

def cross_point(p1: complex, p2: complex, p3: complex, p4: complex) -> complex:
	base = p4 - p3
	hypo1 = p1 - p3
	hypo2 = p2 - p3
	d1 = abs(cross(base, hypo1)) / abs(base)
	d2 = abs(cross(base, hypo2)) / abs(base)
	cross_point = p1 + d1 / (d1 + d2) * (p2 - p1)
	return cross_point
q = int(input())
for _ in range(q):
	(x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3) = map(lambda x: int(x), input().split())
	p0 = complex(x_p0, y_p0)
	p1 = complex(x_p1, y_p1)
	p2 = complex(x_p2, y_p2)
	p3 = complex(x_p3, y_p3)
	ans = cross_point(p0, p1, p2, p3)
	print(f'{ans.real} {ans.imag}')


def vc(p, q):
	return [p[0] - q[0], p[1] - q[1]]

def cross(u, v):
	return u[0] * v[1] - u[1] * v[0]
n = int(input())
for _ in range(n):
	(x0, y0, x1, y1, x2, y2, x3, y3) = map(int, input().split())
	(p0, p1, p2, p3) = ([x0, y0], [x1, y1], [x2, y2], [x3, y3])
	v01 = vc(p1, p0)
	v02 = vc(p2, p0)
	v03 = vc(p3, p0)
	d1 = cross(v01, v02)
	d2 = cross(v01, v03)
	if d1 == 0:
		print(*p2)
	elif d2 == 0:
		print(*p3)
	else:
		mu = abs(d1) / (abs(d1) + abs(d2))
		v23 = vc(p3, p2)
		ans = [p2[0] + mu * v23[0], p2[1] + mu * v23[1]]
		print(*ans)


def intersection_ll(S0, S1, T0, T1):
	(x0, y0) = S0
	(x1, y1) = S1
	(X0, X1) = T0
	(X1, Y1) = T1
	p = (x1 - x0) * (y0 - Y0) - (y1 - y0) * (x0 - X0)
	q = (x1 - x0) * (Y1 - Y0) - (y1 - y0) * (X1 - X0)
	return (X0 + p * (X1 - X0) / float(q), Y0 + p * (Y1 - Y0) / float(q))
n = int(input())
for i in range(n):
	(x0, y0, x1, y1, X0, Y0, X1, Y1) = map(int, input().split())
	print('%.08f %.08f' % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1)))


import cmath
import math
import os
import sys
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7
PI = cmath.pi
TAU = cmath.pi * 2
EPS = 1e-10

class Point:
	CCW_COUNTER_CLOCKWISE = 1
	CCW_CLOCKWISE = -1
	CCW_ONLINE_BACK = 2
	CCW_ONLINE_FRONT = -2
	CCW_ON_SEGMENT = 0

	def __init__(self, c: complex):
		self.c = c

	@property
	def x(self):
		return self.c.real

	@property
	def y(self):
		return self.c.imag

	@staticmethod
	def from_rect(x: float, y: float):
		return Point(complex(x, y))

	@staticmethod
	def from_polar(r: float, phi: float):
		return Point(cmath.rect(r, phi))

	def __add__(self, p):
		return Point(self.c + p.c)

	def __iadd__(self, p):
		self.c += p.c
		return self

	def __sub__(self, p):
		return Point(self.c - p.c)

	def __isub__(self, p):
		self.c -= p.c
		return self

	def __mul__(self, f: float):
		return Point(self.c * f)

	def __imul__(self, f: float):
		self.c *= f
		return self

	def __truediv__(self, f: float):
		return Point(self.c / f)

	def __itruediv__(self, f: float):
		self.c /= f
		return self

	def __repr__(self):
		return '({}, {})'.format(round(self.x, 10), round(self.y, 10))

	def __neg__(self):
		return Point(-self.c)

	def __eq__(self, p):
		return abs(self.c - p.c) < EPS

	def __abs__(self):
		return abs(self.c)

	@staticmethod
	def ccw(a, b, c):
		b = b - a
		c = c - a
		det = b.det(c)
		if det > EPS:
			return Point.CCW_COUNTER_CLOCKWISE
		if det < -EPS:
			return Point.CCW_CLOCKWISE
		if b.dot(c) < -EPS:
			return Point.CCW_ONLINE_BACK
		if c.norm() - b.norm() > EPS:
			return Point.CCW_ONLINE_FRONT
		return Point.CCW_ON_SEGMENT

	def dot(self, p):
		return self.x * p.x + self.y * p.y

	def det(self, p):
		return self.x * p.y - self.y * p.x

	def dist(self, p):
		return abs(self.c - p.c)

	def norm(self):
		return abs(self.c)

	def phase(self):
		return cmath.phase(self.c)

	def angle(self, p, q):
		return (cmath.phase(q.c - self.c) - cmath.phase(p.c - self.c) + PI) % TAU - PI

	def area(self, p, q):
		return abs((p - self).det(q - self) / 2)

	def projection_point(self, p, q, allow_outer=False):
		diff_q = q - p
		r = (self - p).dot(diff_q) / abs(diff_q)
		phase = diff_q.phase()
		ret = Point.from_polar(r, phase) + p
		if allow_outer or (p - ret).dot(q - ret) < EPS:
			return ret
		return None

	def reflection_point(self, p, q):
		r = abs(self - p)
		angle = p.angle(q, self)
		angle = (q - p).phase() - angle
		return Point.from_polar(r, angle) + p

	def on_segment(self, p, q, allow_side=True):
		if not allow_side and (self == p or self == q):
			return False
		return abs((p - self).det(q - self)) < EPS and (p - self).dot(q - self) < EPS

class Line:

	def __init__(self, a: float, b: float, c: float):
		self.a = a
		self.b = b
		self.c = c

	@staticmethod
	def from_gradient(grad: float, intercept: float):
		return Line(grad, -1, intercept)

	@staticmethod
	def from_segment(p1, p2):
		a = p2.y - p1.y
		b = p1.x - p2.x
		c = p2.y * (p2.x - p1.x) - p2.x * (p2.y - p1.y)
		return Line(a, b, c)

	@property
	def gradient(self):
		return INF if self.b == 0 else -self.a / self.b

	@property
	def intercept(self):
		return INF if self.b == 0 else -self.c / self.b

	def is_parallel_to(self, l):
		return abs(Point.from_rect(self.a, self.b).det(Point.from_rect(l.a, l.b))) < EPS

	def is_orthogonal_to(self, l):
		return abs(Point.from_rect(self.a, self.b).dot(Point.from_rect(l.a, l.b))) < EPS

	def intersection_point(self, l):
		(a1, b1, c1) = (self.a, self.b, self.c)
		(a2, b2, c2) = (l.a, l.b, l.c)
		det = a1 * b2 - a2 * b1
		if abs(det) < EPS:
			return None
		x = (b1 * c2 - b2 * c1) / det
		y = (a2 * c1 - a1 * c2) / det
		return Point.from_rect(x, y)

	def dist(self, p):
		raise NotImplementedError()

	def has_point(self, p):
		return abs(self.a * p.x + self.b * p.y + self.c) < EPS

class Segment:

	def __init__(self, p1, p2):
		self.p1 = p1
		self.p2 = p2

	def norm(self):
		return abs(self.p1 - self.p2)

	def phase(self):
		return cmath.phase(self.p2 - self.p1)

	def is_parallel_to(self, s):
		return abs((self.p1 - self.p2).det(s.p1 - s.p2)) < EPS

	def is_orthogonal_to(self, s):
		return abs((self.p1 - self.p2).dot(s.p1 - s.p2)) < EPS

	def intersects_with(self, s, allow_side=True):
		if self.is_parallel_to(s):
			return s.p1.on_segment(self.p1, self.p2, allow_side) or s.p2.on_segment(self.p1, self.p2, allow_side) or self.p1.on_segment(s.p1, s.p2, allow_side) or self.p2.on_segment(s.p1, s.p2, allow_side)
		else:
			det_lower = EPS if allow_side else -EPS
			ok = True
			ok &= (self.p2 - self.p1).det(s.p1 - self.p1) * (self.p2 - self.p1).det(s.p2 - self.p1) < det_lower
			ok &= (s.p2 - s.p1).det(self.p1 - s.p1) * (s.p2 - s.p1).det(self.p2 - s.p1) < det_lower
			return ok

	def closest_point(self, p):
		d = (p - self.p1).dot(self.p2 - self.p1) / self.norm()
		if d < EPS:
			return self.p1
		if -EPS < d - self.norm():
			return self.p2
		return Point.from_polar(d, (self.p2 - self.p1).phase()) + self.p1

	def dist(self, p):
		return abs(p - self.closest_point(p))

	def dist_segment(self, s):
		if self.intersects_with(s):
			return 0.0
		return min(self.dist(s.p1), self.dist(s.p2), s.dist(self.p1), s.dist(self.p2))

	def has_point(self, p, allow_side=True):
		return p.on_segment(self.p1, self.p2, allow_side=allow_side)

class Polygon:

	def __init__(self, points):
		self.points = points

	def iter2(self):
		return zip(self.points, self.points[1:] + self.points[:1])

	def iter3(self):
		return zip(self.points, self.points[1:] + self.points[:1], self.points[2:] + self.points[:2])

	def area(self):
		dets = []
		for (p, q) in self.iter2():
			dets.append(p.det(q))
		return abs(math.fsum(dets)) / 2

	def is_convex(self, allow_straight=False, allow_collapsed=False):
		ccw = []
		for (a, b, c) in self.iter3():
			ccw.append(Point.ccw(a, b, c))
		ccw = set(ccw)
		if len(ccw) == 1:
			if ccw == {Point.CCW_CLOCKWISE}:
				return True
			if ccw == {Point.CCW_COUNTER_CLOCKWISE}:
				return True
		if allow_straight and len(ccw) == 2:
			if ccw == {Point.CCW_ONLINE_FRONT, Point.CCW_CLOCKWISE}:
				return True
			if ccw == {Point.CCW_ONLINE_FRONT, Point.CCW_COUNTER_CLOCKWISE}:
				return True
		if allow_collapsed and len(ccw) == 3:
			return ccw == {Point.CCW_ONLINE_FRONT, Point.CCW_ONLINE_BACK, Point.CCW_ON_SEGMENT}
		return False

	def has_point_on_edge(self, p):
		for (a, b) in self.iter2():
			if p.on_segment(a, b):
				return True
		return False

	def contains(self, p, allow_on_edge=True):
		angles = []
		for (a, b) in self.iter2():
			if p.on_segment(a, b):
				return allow_on_edge
			angles.append(p.angle(a, b))
		return abs(math.fsum(angles)) > EPS

	@staticmethod
	def convex_hull(points, allow_straight=False):
		points = points[:]
		points.sort(key=lambda p: (p.x, p.y))
		det_lower = -EPS if allow_straight else EPS
		sz = 0
		ret = [None] * (N * 2)
		for p in points:
			while sz > 1 and (ret[sz - 1] - ret[sz - 2]).det(p - ret[sz - 1]) < det_lower:
				sz -= 1
			ret[sz] = p
			sz += 1
		floor = sz
		for p in reversed(points[:-1]):
			while sz > floor and (ret[sz - 1] - ret[sz - 2]).det(p - ret[sz - 1]) < det_lower:
				sz -= 1
			ret[sz] = p
			sz += 1
		ret = ret[:sz - 1]
		if allow_straight and len(ret) > len(points):
			ret = points
		return ret

	@staticmethod
	def diameter(points):
		points = Polygon.convex_hull(points, allow_straight=False)
		if len(points) == 1:
			return 0.0
		if len(points) == 2:
			return abs(points[0] - points[1])
		si = points.index(min(points, key=lambda p: (p.x, p.y)))
		sj = points.index(max(points, key=lambda p: (p.x, p.y)))
		n = len(points)
		ret = 0.0
		(i, j) = (si, sj)
		while i != sj or j != si:
			ret = max(ret, abs(points[i] - points[j]))
			ni = (i + 1) % n
			nj = (j + 1) % n
			if (points[ni] - points[i]).det(points[nj] - points[j]) > 0:
				j = nj
			else:
				i = ni
		return ret

	def convex_cut_by_line(self, line_p1, line_p2):
		n = len(self.points)
		line = Line.from_segment(line_p1, line_p2)
		on_line_points = []
		for (i, p) in enumerate(self.points):
			if line.has_point(p):
				on_line_points.append(i)
		has_on_line_edge = False
		if len(on_line_points) >= 3:
			has_on_line_edge = True
		elif len(on_line_points) == 2:
			has_on_line_edge = abs(on_line_points[0] - on_line_points[1]) in [1, n - 1]
		if has_on_line_edge:
			for p in self.points:
				ccw = Point.ccw(line_p1, line_p2, p)
				if ccw == Point.CCW_COUNTER_CLOCKWISE:
					return (Polygon(self.points[:]), None)
				if ccw == Point.CCW_CLOCKWISE:
					return (None, Polygon(self.points[:]))
		ret_lefts = []
		ret_rights = []
		d = line_p2 - line_p1
		for (p, q) in self.iter2():
			det_p = d.det(p - line_p1)
			det_q = d.det(q - line_p1)
			if det_p > -EPS:
				ret_lefts.append(p)
			if det_p < EPS:
				ret_rights.append(p)
			if det_p * det_q < -EPS:
				intersection = line.intersection_point(Line.from_segment(p, q))
				ret_lefts.append(intersection)
				ret_rights.append(intersection)
		l = Polygon(ret_lefts) if len(ret_lefts) > 1 else None
		r = Polygon(ret_rights) if len(ret_rights) > 1 else None
		return (l, r)
Q = int(sys.stdin.buffer.readline())
ROWS = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]
for (x0, y0, x1, y1, x2, y2, x3, y3) in ROWS:
	l1 = Line.from_segment(Point.from_rect(x0, y0), Point.from_rect(x1, y1))
	l2 = Line.from_segment(Point.from_rect(x2, y2), Point.from_rect(x3, y3))
	ans = l1.intersection_point(l2)
	print('{:.10f} {:.10f}'.format(ans.x, ans.y))


q = int(input())
for _ in range(q):
	(x0, y0, x1, y1, x2, y2, x3, y3) = map(int, input().split())
	s = (x3 - x2) * (y0 - y2) - (x0 - x2) * (y3 - y2)
	t = (x1 - x0) * (y3 - y2) - (x3 - x2) * (y1 - y0)
	u = s / t
	print(x0 + u * (x1 - x0), y0 + u * (y1 - y0))


import collections
import math

class Vector2(collections.namedtuple('Vector2', ['x', 'y'])):

	def __add__(self, other):
		return Vector2(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Vector2(self.x - other.x, self.y - other.y)

	def __mul__(self, scalar):
		return Vector2(self.x * scalar, self.y * scalar)

	def __neg__(self):
		return Vector2(-self.x, -self.y)

	def __pos__(self):
		return Vector2(+self.x, +self.y)

	def __abs__(self):
		return math.sqrt(float(self.x * self.x + self.y * self.y))

	def dot(self, other):
		return self.x * other.x + self.y * other.y

	def cross(self, other):
		return self.x * other.y - self.y * other.x

def getDistanceSP(segment, point):
	p = point
	(p1, p2) = segment
	if (p2 - p1).dot(p - p1) < 0:
		return abs(p - p1)
	if (p1 - p2).dot(p - p2) < 0:
		return abs(p - p2)
	return abs((p2 - p1).cross(p - p1)) / abs(p2 - p1)

def getDistance(s1, s2):
	(a, b) = s1
	(c, d) = s2
	if intersect(s1, s2):
		return 0
	return min(getDistanceSP(s1, c), getDistanceSP(s1, d), getDistanceSP(s2, a), getDistanceSP(s2, b))

def ccw(p0, p1, p2):
	a = p1 - p0
	b = p2 - p0
	if a.cross(b) > 0:
		return 1
	elif a.cross(b) < 0:
		return -1
	elif a.dot(b) < 0:
		return 2
	elif abs(a) < abs(b):
		return -2
	else:
		return 0

def intersect(s1, s2):
	(a, b) = s1
	(c, d) = s2
	return ccw(a, b, c) * ccw(a, b, d) <= 0 and ccw(c, d, a) * ccw(c, d, b) <= 0

def getCrossPoint(s1, s2):
	(a, b) = s1
	(c, d) = s2
	base = d - c
	d1 = abs(base.cross(a - c))
	d2 = abs(base.cross(b - c))
	t = d1 / (d1 + d2)
	return a + (b - a) * t
n = int(input())
for _ in range(n):
	l = list(map(int, input().split()))
	s1 = [Vector2(l[0], l[1]), Vector2(l[2], l[3])]
	s2 = [Vector2(l[4], l[5]), Vector2(l[6], l[7])]
	x = getCrossPoint(s1, s2)
	print(x.x, x.y)


import sys
from itertools import starmap
readline = sys.stdin.readline
EPS = 1e-09
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2

class Segment(object):
	__slots__ = ('fi', 'se')

	def __init__(self, fi, se):
		self.fi = fi
		self.se = se

def cross(a, b):
	return a.real * b.imag - a.imag * b.real

def dot(a, b):
	return a.real * b.real + a.imag * b.imag

def norm(base):
	return abs(base) ** 2

def project(s, p2):
	base = s.fi - s.se
	r = dot(p2 - s.fi, base) / norm(base)
	return s.fi + base * r

def reflect(s, p):
	return p + (project(s, p) - p) * 2.0

def ccw(p1, p2, p3):
	a = p2 - p1
	b = p3 - p1
	if cross(a, b) > EPS:
		return 1
	if cross(a, b) < -EPS:
		return -1
	if dot(a, b) < -EPS:
		return 2
	if norm(a) < norm(b):
		return -2
	return 0

def intersect4(p1, p2, p3, p4):
	return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0

def intersect2(s1, s2):
	return intersect4(s1.fi, s1.se, s2.fi, s2.se)

def getDistance(a, b):
	return abs(a - b)

def getDistanceLP(l, p):
	return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))

def getDistanceSP(s, p):
	if dot(s.se - s.fi, p - s.fi) < 0.0:
		return abs(p - s.fi)
	if dot(s.fi - s.se, p - s.se) < 0.0:
		return abs(p - s.se)
	return getDistanceLP(s, p)

def getDistances(s1, s2):
	if intersect2(s1, s2):
		return 0.0
	return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se), getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))

def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
n = int(readline())
for _ in [0] * n:
	(p0, p1, p2, p3) = starmap(complex, zip(*[map(int, input().split())] * 2))
	p = getCrossPoint(Segment(p0, p1), Segment(p2, p3))
	print('{0:.10f} {1:.10f}'.format(p.real, p.imag))


import sys

class Segment(object):
	__slots__ = ('source', 'target')

	def __init__(self, source, target):
		self.source = complex(source)
		self.target = complex(target)

def cross(a, b):
	return a.real * b.imag - a.imag * b.real

def dot(a, b):
	return a.real * b.real + a.imag * b.imag

def get_cross_point(s1, s2):
	base_vector = s2.target - s2.source
	d1 = abs(cross(base_vector, s1.source - s2.source))
	d2 = abs(cross(base_vector, s1.target - s2.source))
	t = d1 / (d1 + d2)
	cross_point = s1.source + (s1.target - s1.source) * t
	print('{real:.10f} {imag:.10f}'.format(real=cross_point.real, imag=cross_point.imag))
	return None

def solve(_lines):
	for line in _lines:
		line = tuple(map(int, line))
		(p0, p1, p2, p3) = (x + y * 1j for (x, y) in zip(line[::2], line[1::2]))
		(s1, s2) = (Segment(p0, p1), Segment(p2, p3))
		get_cross_point(s1, s2)
	return None
_input = sys.stdin.readlines()
l_num = int(_input[0])
lines = map(lambda x: x.split(), _input[1:])
solve(lines)


import math
EPS = 1e-14

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __sub__(self, p):
		return Point(self.x - p.x, self.y - p.y)

	def __add__(self, p):
		return Point(self.x + p.x, self.y + p.y)

	def __mul__(self, a):
		return Point(self.x * a, self.y * a)

	def __truediv__(self, a):
		return Point(self.x / a, self.y / a)

	def __str__(self):
		return str(self.x) + ',' + str(self.y)

	def __repr__(self):
		return 'Point(' + str(self.x) + ',' + str(self.y) + ')'

	def __lt__(self, other):
		if self.y - other.y == 0:
			return self.x < other.x
		else:
			return self.y < other.y

	def __eq__(self, other):
		return abs(self.x - other.x) < EPS and abs(self.y - other.y) < EPS

class Segment:

	def __init__(self, p1, p2):
		self.p1 = p1
		self.p2 = p2

	def __str__(self):
		return 'segment:(' + str(self.p1) + ';' + str(self.p2) + ')'

	def __repr__(self):
		return 'segment:(' + str(self.p1) + ';' + str(self.p2) + ')'

class Circle:

	def __init__(self, c, r):
		self.c = c
		self.r = r

	def __str__(self):
		return 'Circle:(center point: ' + str(self.c) + '; radius: ' + str(self.r) + ')'

	def __repr__(self):
		return 'Circle:(center point: ' + str(self.c) + '; radius: ' + str(self.r) + ')'

class Polygon:

	def __init__(self, ps=[]):
		self.ps = ps
		self.size = len(ps)

	def __getitem__(self, i):
		return self.ps[i]

	def __setitem__(self, i, p):
		self.ps[i] = p

	def __iter__(self):
		return self.ps

	def addpoint(self, i, p):
		self.ps.insert(i, p)
		self.size += 1

	def delpoint(self, i):
		self.size -= 1
		return self.ps.pop(i)

	def sortYX(self):
		self.ps.sort()

	def __str__(self):
		return 'Polygon:' + str(tuple(self.ps))

	def __repr__(self):
		return 'Polygon:' + str(tuple(self.ps))

	def __len__(self):
		return len(self.ps)

	def __eq__(self, other):
		return self.ps == other.ps

	def draw(self):
		turtle.screensize(800, 800, 'black')
		turtle.title('Polygon convex hull')
		turtle.setworldcoordinates(-400, -400, 400, 400)
		t = turtle.Turtle()
		t.pencolor('red')
		for pt in self.ps:
			t.goto(pt.x, pt.y)
			t.dot(10, 'white')

def norm(p):
	return p.x * p.x + p.y * p.y

def length(p):
	return math.sqrt(p.x * p.x + p.y * p.y)

def dot(a, b):
	return a.x * b.x + a.y * b.y

def cross(a, b):
	return a.x * b.y - a.y * b.x

def project(s, p):
	base = s.p2 - s.p1
	r = dot(p - s.p1, base) / norm(base)
	return s.p1 + base * r

def getDistance(a, b):
	return length(a - b)

def getDistanceLP(l, p):
	return abs(cross(l.p2 - l.p1, p - l.p1) / length(l.p2 - l.p1))

def getDistanceSP(s, p):
	if dot(s.p2 - s.p1, p - s.p1) < 0.0:
		return length(p - s.p1)
	if dot(s.p1 - s.p2, p - s.p2) < 0.0:
		return length(p - s.p2)
	return getDistanceLP(s, p)

def isOrthogonalSG(s1, s2):
	return abs(dot(s1.p2 - s1.p1, s2.p2 - s2.p1)) < EPS

def isParallelLN(s1, s2):
	return abs(cross(s1.p2 - s1.p1, s2.p2 - s2.p1)) < 0
COUNTER_CLOCKWISE = 1
CLOCKWISE = -1
ONLINE_BACK = -2
ONLINE_FRONT = 2
ON_SEGMENT = 0

def ccw(p0, p1, p2):
	a = p1 - p0
	b = p2 - p0
	if cross(a, b) > EPS:
		return COUNTER_CLOCKWISE
	if cross(a, b) < -EPS:
		return CLOCKWISE
	if dot(a, b) < -EPS:
		return ONLINE_BACK
	if norm(a) < norm(b):
		return ONLINE_FRONT
	return ON_SEGMENT

def toleft(p0, p1, p2):
	a = p1 - p0
	b = p2 - p0
	tmp = cross(a, b)
	if tmp > EPS:
		return 1
	elif abs(tmp) < EPS and norm(a) <= norm(b):
		return 2
	elif abs(tmp) < EPS and norm(a) > norm(b):
		return -2
	else:
		return -1

def reflect(s, p):
	return p + (project(s, p) - p) * 2.0

def intersectSG(s1, s2):
	return intersectP4(s1.p1, s1.p2, s2.p1, s2.p2)

def getDistanceSG(s1, s2):
	if intersectSG(s1, s2):
		return 0.0
	return min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2), getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2))

def intersectP4(p1, p2, p3, p4):
	return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0

def getCrossPoint(s1, s2):
	base = s2.p2 - s2.p1
	d1 = abs(cross(base, s1.p1 - s2.p1))
	d2 = abs(cross(base, s1.p2 - s2.p1))
	if d1 + d2 == 0:
		return s2.p1
	t = d1 / (d1 + d2)
	return s1.p1 + (s1.p2 - s1.p1) * t
q = int(input())
for i in range(0, q):
	s = [int(x) for x in input().split()]
	p0 = Point(s[0], s[1])
	p1 = Point(s[2], s[3])
	p2 = Point(s[4], s[5])
	p3 = Point(s[6], s[7])
	s1 = Segment(p0, p1)
	s2 = Segment(p2, p3)
	if p0 == p2 or p0 == p3:
		print('{:.12f} {:.12f}'.format(p0.x, p0.y))
	elif p1 == p2 or p1 == p3:
		print('{:.12f} {:.12f}'.format(p1.x, p1.y))
	else:
		rt = getCrossPoint(s1, s2)
		print('{:.12f} {:.12f}'.format(rt.x, rt.y))


from itertools import starmap

def cross(a, b):
	return a.real * b.imag - a.imag * b.real
q = int(input())
while q:
	q -= 1
	(p0, p1, p2, p3) = starmap(complex, zip(*[map(int, input().split())] * 2))
	(d1, d2) = (abs(cross(p3 - p2, p0 - p2)), abs(cross(p3 - p2, p1 - p2)))
	c = p0 + (p1 - p0) * d1 / (d1 + d2)
	print(c.real, c.imag)


class Line:

	def __init__(self, p1, p2):
		if p1[1] < p2[1]:
			self.s = p2
			self.e = p1
		elif p1[1] > p2[1]:
			self.s = p1
			self.e = p2
		elif p1[0] < p2[0]:
			self.s = p1
			self.e = p2
		else:
			self.s = p2
			self.e = p1

def cross(a, b):
	return a[0] * b[1] - a[1] * b[0]

def CrossPoint(l, m):
	crsl = cross(l.s, l.e)
	crsm = cross(m.s, m.e)
	det = (l.s[1] - l.e[1]) * (m.e[0] - m.s[0]) - (l.e[0] - l.s[0]) * (m.s[1] - m.e[1])
	x = (m.s[0] - m.e[0]) * crsl + (l.e[0] - l.s[0]) * crsm
	y = (m.s[1] - m.e[1]) * crsl + (l.e[1] - l.s[1]) * crsm
	return [x / det, y / det]
q = int(input())
for i in range(q):
	(x0, y0, x1, y1, x2, y2, x3, y3) = [int(i) for i in input().split()]
	l = Line([x0, y0], [x1, y1])
	m = Line([x2, y2], [x3, y3])
	P = CrossPoint(l, m)
	print(P[0], P[1])


import sys
from itertools import starmap
readline = sys.stdin.readline
EPS = 1e-09
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2

class Segment(object):
	__slots__ = ('fi', 'se')

	def __init__(self, fi, se):
		self.fi = fi
		self.se = se

def cross(a, b):
	return a.real * b.imag - a.imag * b.real

def dot(a, b):
	return a.real * b.real + a.imag * b.imag

def norm(base):
	return abs(base) ** 2

def project(s, p2):
	base = s.fi - s.se
	r = dot(p2 - s.fi, base) / norm(base)
	return s.fi + base * r

def reflect(s, p):
	return p + (project(s, p) - p) * 2.0

def ccw(p1, p2, p3):
	a = p2 - p1
	b = p3 - p1
	if cross(a, b) > EPS:
		return 1
	if cross(a, b) < -EPS:
		return -1
	if dot(a, b) < -EPS:
		return 2
	if norm(a) < norm(b):
		return -2
	return 0

def intersect4(p1, p2, p3, p4):
	return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0

def intersect2(s1, s2):
	return intersect4(s1.fi, s1.se, s2.fi, s2.se)

def getDistance(a, b):
	return abs(a - b)

def getDistanceLP(l, p):
	return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))

def getDistanceSP(s, p):
	if dot(s.se - s.fi, p - s.fi) < 0.0:
		return abs(p - s.fi)
	if dot(s.fi - s.se, p - s.se) < 0.0:
		return abs(p - s.se)
	return getDistanceLP(s, p)

def getDistances(s1, s2):
	if intersect2(s1, s2):
		return 0.0
	return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se), getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))

def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
n = int(readline())
for _ in [0] * n:
	(p0, p1, p2, p3) = starmap(complex, zip(*[map(int, readline().split())] * 2))
	p = getCrossPoint(Segment(p0, p1), Segment(p2, p3))
	print('{0:.10f} {1:.10f}'.format(p.real, p.imag))


def cross(c1, c2):
	return c1.real * c2.imag - c1.imag * c2.real

def print_cross_point(p1, p2, p3, p4):
	base = p4 - p3
	hypo1 = p1 - p3
	hypo2 = p2 - p3
	d1 = abs(cross(base, hypo1)) / abs(base)
	d2 = abs(cross(base, hypo2)) / abs(base)
	cp = p1 + d1 / (d1 + d2) * (p2 - p1)
	print('{0:.10f} {1:.10f}'.format(cp.real, cp.imag))
import sys
file_input = sys.stdin
sq = file_input.readline()
for line in file_input:
	(x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3) = map(int, line.split())
	p0 = x_p0 + y_p0 * 1j
	p1 = x_p1 + y_p1 * 1j
	p2 = x_p2 + y_p2 * 1j
	p3 = x_p3 + y_p3 * 1j
	print_cross_point(p0, p1, p2, p3)


import math

class Vector:

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __add__(self, other):
		return Vector(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Vector(self.x - other.x, self.y - other.y)

	def __mul__(self, scalar):
		return Vector(self.x * scalar, self.y * scalar)

	def __rmul__(self, scalar):
		return Vector(self.x * scalar, self.y * scalar)

	def __repr__(self):
		return str([self.x, self.y])

	def norm_2(self):
		return dot(self, self)

	def norm(self):
		return math.sqrt(self.norm_2())

def v_sum(v1, v2):
	return Vector(v1.x + v2.x, v1.y + v2.y)

def scalar_multi(k, v):
	return Vector(k * v.x, k * v.y)

def v_diff(v1, v2):
	return v_sum(v1, scalar_multi(-1, v2))

def dot(vector1, vector2):
	return vector1.x * vector2.x + vector1.y * vector2.y

def cross(vector1, vector2):
	return vector1.x * vector2.y - vector1.y * vector2.x
q = int(input())
for i in range(q):
	(x1, y1, x2, y2, x3, y3, x4, y4) = map(float, input().split())
	p1 = Vector(x1, y1)
	p2 = Vector(x2, y2)
	p3 = Vector(x3, y3)
	p4 = Vector(x4, y4)
	k = cross(p2 - p4, p3 - p4) / cross(p3 - p4, p1 - p2)
	ans = k * (p1 - p2) + p2
	print('{} {}'.format(ans.x, ans.y))


def cp(a, b, c, d, e, f, g, h):
	A = a * d - b * c
	B = e * h - f * g
	C = d - b
	D = e - g
	E = c - a
	F = f - h
	det = C * D - E * F
	return [(A * D + B * E) / det, (A * F + B * C) / det]
q = int(input())
for i in range(q):
	(a, b, c, d, e, f, g, h) = [int(i) for i in input().split()]
	P = cp(a, b, c, d, e, f, g, h)
	print(P[0], P[1])


from sys import stdin
readline = stdin.readline

def main():
	q = int(readline())
	for i in range(q):
		xy = map(int, readline().split())
		(p0, p1, p2, p3) = [x + y * 1j for (x, y) in zip(*[xy] * 2)]
		c1 = intersection(p0, p2, p1, p3)
		print('{:.10f} {:.10f}'.format(c1.real, c1.imag))

def intersection(p1, p2, p3, p4):
	a1 = p4 - p2
	b1 = p2 - p3
	b2 = p1 - p2
	s1 = cross(a1, b2) / 2
	s2 = cross(a1, b1) / 2
	c1 = p1 + (p3 - p1) * s1 / (s1 + s2)
	return c1

def cross(a, b):
	return a.real * b.imag - a.imag * b.real
main()


import sys, math, os
PYDEV = os.environ.get('PYDEV')
if PYDEV == 'True':
	sys.stdin = open('sample-input.txt', 'rt')
n = int(input())
for k in range(n):
	(x1, y1, x2, y2, x3, y3, x4, y4) = [int(_) for _ in input().split()]
	x = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4))
	y = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4))
	print('%.10f %.10f' % (x, y))


import sys
sys.setrecursionlimit(10 ** 9)

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))
INF = float('inf')

class Geometry:
	EPS = 10 ** (-9)

	def add(self, a, b):
		(x1, y1) = a
		(x2, y2) = b
		return (x1 + x2, y1 + y2)

	def sub(self, a, b):
		(x1, y1) = a
		(x2, y2) = b
		return (x1 - x2, y1 - y2)

	def mul(self, a, b):
		(x1, y1) = a
		if not isinstance(b, tuple):
			return (x1 * b, y1 * b)
		(x2, y2) = b
		return (x1 * x2, y1 * y2)

	def abs(self, a):
		from math import hypot
		(x1, y1) = a
		return hypot(x1, y1)

	def norm(self, a):
		(x, y) = a
		return x ** 2 + y ** 2

	def dot(self, a, b):
		(x1, y1) = a
		(x2, y2) = b
		return x1 * x2 + y1 * y2

	def cross(self, a, b):
		(x1, y1) = a
		(x2, y2) = b
		return x1 * y2 - y1 * x2

	def project(self, seg, p):
		(p1, p2) = seg
		base = self.sub(p2, p1)
		r = self.dot(self.sub(p, p1), base) / self.norm(base)
		return self.add(p1, self.mul(base, r))

	def reflect(self, seg, p):
		return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2))

	def ccw(self, p0, p1, p2):
		a = self.sub(p1, p0)
		b = self.sub(p2, p0)
		if self.cross(a, b) > self.EPS:
			return 1
		if self.cross(a, b) < -self.EPS:
			return -1
		if self.dot(a, b) < -self.EPS:
			return 2
		if self.norm(a) < self.norm(b):
			return -2
		return 0

	def intersect(self, seg1, seg2):
		(p1, p2) = seg1
		(p3, p4) = seg2
		return self.ccw(p1, p2, p3) * self.ccw(p1, p2, p4) <= 0 and self.ccw(p3, p4, p1) * self.ccw(p3, p4, p2) <= 0

	def get_distance_LP(self, line, p):
		(p1, p2) = line
		return abs(self.cross(self.sub(p2, p1), self.sub(p, p1)) / self.abs(self.sub(p2, p1)))

	def get_distance_SP(self, seg, p):
		(p1, p2) = seg
		if self.dot(self.sub(p2, p1), self.sub(p, p1)) < 0:
			return self.abs(self.sub(p, p1))
		if self.dot(self.sub(p1, p2), self.sub(p, p2)) < 0:
			return self.abs(self.sub(p, p2))
		return self.get_distance_LP(seg, p)

	def get_distance_SS(self, seg1, seg2):
		(p1, p2) = seg1
		(p3, p4) = seg2
		if self.intersect(seg1, seg2):
			return 0
		return min(self.get_distance_SP(seg1, p3), self.get_distance_SP(seg1, p4), self.get_distance_SP(seg2, p1), self.get_distance_SP(seg2, p2))

	def get_cross_point(self, seg1, seg2):
		(p1, p2) = seg1
		(p3, p4) = seg2
		base = self.sub(p4, p3)
		dist1 = abs(self.cross(base, self.sub(p1, p3)))
		dist2 = abs(self.cross(base, self.sub(p2, p3)))
		t = dist1 / (dist1 + dist2)
		return self.add(p1, self.mul(self.sub(p2, p1), t))
gm = Geometry()
for _ in range(INT()):
	(x1, y1, x2, y2, x3, y3, x4, y4) = MAP()
	seg1 = ((x1, y1), (x2, y2))
	seg2 = ((x3, y3), (x4, y4))
	res = gm.get_cross_point(seg1, seg2)
	print(*res)


def cp(a, b, c, d, e, f, g, h):
	A = a * d - b * c
	B = e * h - f * g
	C = d - b
	D = e - g
	E = c - a
	F = f - h
	det = C * D - E * F
	x = A * D + B * E
	y = A * F + B * C
	return [x / det, y / det]
q = int(input())
for i in range(q):
	(a, b, c, d, e, f, g, h) = [int(i) for i in input().split()]
	P = cp(a, b, c, d, e, f, g, h)
	print(P[0], P[1])


def CrossPoint(p1, p2, p3, p4):
	((x1, y1), (x2, y2), (x3, y3), (x4, y4)) = (p1, p2, p3, p4)
	(a1, b1, c1) = (y1 - y2, x2 - x1, x1 * y2 - x2 * y1)
	(a2, b2, c2) = (y3 - y4, x4 - x3, x3 * y4 - x4 * y3)
	det = a1 * b2 - a2 * b1
	if abs(det) < eps:
		return None
	return ((b1 * c2 - b2 * c1) / det, (a2 * c1 - a1 * c2) / det)
import sys
eps = sys.float_info.epsilon
input = sys.stdin.buffer.readline
ans = []
for _ in range(int(input())):
	m = map(int, input().split())
	ans.append('{} {}'.format(*CrossPoint(*[(x, y) for (x, y) in zip(*[iter(m)] * 2)])))
print(*ans, sep='\n')


from math import pi, cos, sin, atan2
EPS = 10 ** (-9)

def eq(value1, value2):
	return abs(value1 - value2) <= EPS

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y
		self.arg = atan2(y, x)

	def __str__(self):
		return '{0:.8f} {1:.8f}'.format(self.x, self.y)

	def __add__(self, other):
		return Point(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Point(self.x - other.x, self.y - other.y)

	def __mul__(self, scal):
		return Point(self.x * scal, self.y * scal)

	def __truediv__(self, scal):
		return Point(self.x / scal, self.y / scal)

	def __eq__(self, other):
		return eq(self.x, other.x) and eq(self.y, other.y)

	def __abs__(self):
		return (self.x ** 2 + self.y ** 2) ** 0.5

def Rotation(vec: Point, rad):
	return Point(vec.x * cos(rad) - vec.y * sin(rad), vec.x * sin(rad) + vec.y * cos(rad))

class Circle:

	def __init__(self, p, r):
		self.p = p
		self.r = r

class Line:

	def __init__(self, a, b):
		self.a = a
		self.b = b
		self.arg = (a - b).arg % pi

	def __str__(self):
		return '[({0}, {1}) - ({2}, {3})]'.format(self.a.x, self.a.y, self.b.x, self.b.y)

	def par(self, point):
		return Line(point, point + (self.a - self.b))

	def tan(self, point):
		return Line(point, point + Rotation(self.a - self.b, pi / 2))

class Segment(Line):

	def __init__(self, a, b):
		super().__init__(a, b)

def cross(vec1: Point, vec2: Point):
	return vec1.x * vec2.y - vec1.y * vec2.x

def dot(vec1: Point, vec2: Point):
	return vec1.x * vec2.x + vec1.y * vec2.y

def ccw(a, b, c):
	if cross(b - a, c - a) > EPS:
		return +1
	if cross(b - a, c - a) < -EPS:
		return -1
	if dot(c - a, b - a) < -EPS:
		return +2
	if abs(b - a) < abs(c - a):
		return -2
	return 0

def projection(l, p):
	t = dot(l.b - l.a, p - l.a) / abs(l.a - l.b) ** 2
	return l.a + (l.b - l.a) * t

def reflection(l, p):
	return p + (projection(l, p) - p) * 2

def isPararell(l1, l2):
	return eq(cross(l1.a - l1.b, l2.a - l2.b), 0)

def isVertical(l1, l2):
	return eq(dot(l1.a - l1.b, l2.a - l2.b), 0)

def isIntersect_lp(l, p):
	return abs(ccw(l.a, l.b, p)) != 1

def isIntersect_ll(l1, l2):
	return not isPararell(l1, l2) or isIntersect_lp(l1, l2.a)

def isIntersect_sp(s, p):
	return ccw(s.a, s.b, p) == 0

def isIntersect_ss(s1, s2):
	return ccw(s1.a, s1.b, s2.a) * ccw(s1.a, s1.b, s2.b) <= 0 and ccw(s2.a, s2.b, s1.a) * ccw(s2.a, s2.b, s1.b) <= 0

def isIntersect_ls(l, s):
	return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS

def isIntersect_cp(c, p):
	return abs(abs(c.p - p) - c.r) < EPS

def isIntersect_cl(c, l):
	return distance_lp(l, c.p) <= c.r + EPS

def isIntersect_cs(c, s):
	pass

def isIntersect_cc(c1, c2):
	pass

def distance_pp(p1, p2):
	return abs(p1 - p2)

def distance_lp(l, p):
	return abs(projection(l, p) - p)

def distance_ll(l1, l2):
	return 0 if isIntersect_ll(l1, l2) else distance_lp(l1, l2.a)

def distance_sp(s, p):
	r = projection(s, p)
	if isIntersect_sp(s, r):
		return abs(r - p)
	return min(abs(s.a - p), abs(s.b - p))

def distance_ss(s1, s2):
	if isIntersect_ss(s1, s2):
		return 0
	return min([distance_sp(s1, s2.a), distance_sp(s1, s2.b), distance_sp(s2, s1.a), distance_sp(s2, s1.b)])

def distance_ls(l, s):
	if isIntersect_ls(l, s):
		return 0
	return min(distance_lp(l, s.a), distance_lp(l, s.b))

def crosspoint_ll(l1, l2):
	A = cross(l1.b - l1.a, l2.b - l2.a)
	B = cross(l1.b - l1.a, l1.b - l2.a)
	if eq(abs(A), 0) and eq(abs(B), 0):
		return l2.a
	return l2.a + (l2.b - l2.a) * B / A

def crosspoint_ss(s1, s2):
	return crosspoint_ll(s1, s2)

def crosspoint_lc(l, c):
	if eq(distance_lp(l, c.p), c.r):
		return [c.p]
	p = projection(l, c.p)
	e = (l.b - l.a) / abs(l.b - l.a)
	dis = (c.r ** 2 - abs(p - c.p) ** 2) ** 0.5
	return [p + e * dis, p - e * dis]

def crosspoint_sc(s, c):
	pass

def crosspoint_cc(c1, c2):
	d = abs(c1.p - c2.p)
	if not abs(c1.r - c2.r) <= d <= c1.r + c2.r:
		return []
	mid_p = (c2.p * (c1.r ** 2 - c2.r ** 2 + d ** 2) + c1.p * (c2.r ** 2 - c1.r ** 2 + d ** 2)) / (2 * d ** 2)
	tanvec = Rotation(c1.p - c2.p, pi / 2)
	return crosspoint_lc(Line(mid_p, mid_p + tanvec), c1)

def tangent_cp(c, p):
	return crosspoint_cc(c, Circle(p, (abs(p - c.p) ** 2 - c.r ** 2) ** 0.5))
import sys
input = sys.stdin.readline

def verify_1A():
	(p1x, p1y, p2x, p2y) = map(int, input().split())
	l = Line(Point(p1x, p1y), Point(p2x, p2y))
	Q = int(input())
	Query = [list(map(int, input().split())) for _ in range(Q)]
	for (px, py) in Query:
		p = Point(px, py)
		print(projection(l, p))

def verify_1B():
	(p1x, p1y, p2x, p2y) = map(int, input().split())
	l = Line(Point(p1x, p1y), Point(p2x, p2y))
	Q = int(input())
	Query = [list(map(int, input().split())) for _ in range(Q)]
	for (px, py) in Query:
		p = Point(px, py)
		print(reflection(l, p))

def verify_1C():
	(p1x, p1y, p2x, p2y) = map(int, input().split())
	p1 = Point(p1x, p1y)
	p2 = Point(p2x, p2y)
	Q = int(input())
	Query = [list(map(int, input().split())) for _ in range(Q)]
	for (px, py) in Query:
		p = Point(px, py)
		result = ccw(p1, p2, p)
		if result == 1:
			print('COUNTER_CLOCKWISE')
		elif result == -1:
			print('CLOCKWISE')
		elif result == 2:
			print('ONLINE_BACK')
		elif result == -2:
			print('ONLINE_FRONT')
		else:
			print('ON_SEGMENT')

def verify_2A():
	Q = int(input())
	Query = [list(map(int, input().split())) for _ in range(Q)]
	for (p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y) in Query:
		l1 = Line(Point(p0x, p0y), Point(p1x, p1y))
		l2 = Line(Point(p2x, p2y), Point(p3x, p3y))
		if isPararell(l1, l2):
			print(2)
		elif isVertical(l1, l2):
			print(1)
		else:
			print(0)

def verify_2B():
	Q = int(input())
	Query = [list(map(int, input().split())) for _ in range(Q)]
	for (p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y) in Query:
		s1 = Segment(Point(p0x, p0y), Point(p1x, p1y))
		s2 = Segment(Point(p2x, p2y), Point(p3x, p3y))
		if isIntersect_ss(s1, s2):
			print(1)
		else:
			print(0)

def verify_2C():
	Q = int(input())
	Query = [list(map(int, input().split())) for _ in range(Q)]
	for (p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y) in Query:
		s1 = Segment(Point(p0x, p0y), Point(p1x, p1y))
		s2 = Segment(Point(p2x, p2y), Point(p3x, p3y))
		print(crosspoint_ss(s1, s2))
verify_2C()


def crossing_point(p0, p1, p2, p3):
	(x0, y0) = p0
	(x1, y1) = p1
	(x2, y2) = p2
	(x3, y3) = p3
	if x0 != x1 and x2 != x3:
		a0 = (y0 - y1) / (x0 - x1)
		b0 = (x1 * y0 - y1 * x0) / (x1 - x0)
		a1 = (y2 - y3) / (x2 - x3)
		b1 = (x3 * y2 - y3 * x2) / (x3 - x2)
		return ((b0 - b1) / (a1 - a0), (a1 * b0 - a0 * b1) / (a1 - a0))
	elif x0 != x1:
		a0 = (y0 - y1) / (x0 - x1)
		b0 = (x1 * y0 - y1 * x0) / (x1 - x0)
		return (x2, a0 * x2 + b0)
	elif x2 != x3:
		a1 = (y2 - y3) / (x2 - x3)
		b1 = (x3 * y2 - y3 * x2) / (x3 - x2)
		return (x0, a1 * x0 + b1)
	else:
		raise ValueError('p0p1 and p2p3 is parallel')

def run():
	q = int(input())
	for _ in range(q):
		(x0, y0, x1, y1, x2, y2, x3, y3) = [int(i) for i in input().split()]
		(x, y) = crossing_point((x0, y0), (x1, y1), (x2, y2), (x3, y3))
		print('{:.10f} {:.10f}'.format(x, y))
run()


q = int(input())
for i in range(q):
	(a, b, c, d, e, f, g, h) = [int(i) for i in input().split()]
	A = d - b
	B = c - a
	C = f - h
	D = e - g
	E = a * d - b * c
	F = e * h - f * g
	G = A * D - B * C
	print((E * D + F * B) / G, (E * C + F * A) / G)


def cross(a, b):
	return a.real * b.imag - a.imag * b.real

def intersection(p0, p1, p2, p3):
	a1 = p3 - p2
	b1 = p0 - p2
	b2 = p1 - p2
	s1 = cross(b1, a1)
	s2 = cross(a1, b2)
	c1 = p0 + (p1 - p0) * s1 / (s1 + s2)
	return c1
q = int(input())
for _ in [0] * q:
	x_y = map(int, input().split())
	(p0, p1, p2, p3) = [x + y * 1j for (x, y) in zip(*[x_y] * 2)]
	c1 = intersection(p0, p1, p2, p3)
	print('{:.10f} {:.10f}'.format(c1.real, c1.imag))


EPS = 10 ** (-9)

def is_equal(a, b):
	return abs(a - b) < EPS

def norm(v, i=2):
	import math
	ret = 0
	n = len(v)
	for j in range(n):
		ret += abs(v[j]) ** i
	return math.pow(ret, 1 / i)

class Vector(list):

	def __add__(self, other):
		n = len(self)
		ret = [0] * n
		for i in range(n):
			ret[i] = super().__getitem__(i) + other.__getitem__(i)
		return self.__class__(ret)

	def __radd__(self, other):
		n = len(self)
		ret = [0] * n
		for i in range(n):
			ret[i] = other.__getitem__(i) + super().__getitem__(i)
		return self.__class__(ret)

	def __iadd__(self, other):
		n = len(self)
		for i in range(n):
			self[i] += other.__getitem__(i)
		return self

	def __sub__(self, others):
		n = len(self)
		ret = [0] * n
		for i in range(n):
			ret[i] = super().__getitem__(i) - others.__getitem__(i)
		return self.__class__(ret)

	def __isub__(self, other):
		n = len(self)
		for i in range(n):
			self[i] -= other.__getitem__(i)
		return self

	def __rsub__(self, others):
		n = len(self)
		ret = [0] * n
		for i in range(n):
			ret[i] = others.__getitem__(i) - super().__getitem__(i)
		return self.__class__(ret)

	def __mul__(self, other):
		n = len(self)
		if isinstance(other, list):
			ret = 0
			for i in range(n):
				ret += super().__getitem__(i) * other.__getitem__(i)
			return ret
		else:
			ret = [0] * n
			for i in range(n):
				ret[i] = super().__getitem__(i) * other
			return self.__class__(ret)

	def __rmul__(self, other):
		n = len(self)
		if isinstance(other, list):
			ret = 0
			for i in range(n):
				ret += super().__getitem__(i) * other.__getitem__(i)
			return ret
		else:
			ret = [0] * n
			for i in range(n):
				ret[i] = super().__getitem__(i) * other
			return self.__class__(ret)

	def __truediv__(self, other):
		n = len(self)
		ret = [0] * n
		for i in range(n):
			ret[i] = super().__getitem__(i) / other
		return self.__class__(ret)

	def norm(self, i):
		return norm(self, i)

	def __pow__(self, other):
		n = len(self)
		ret = [0] * 3
		x = self[:]
		y = other[:]
		if n == 2:
			x.append(0)
			y.append(0)
		if n == 2 or n == 3:
			for i in range(3):
				(ret[0], ret[1], ret[2]) = (x[1] * y[2] - x[2] * y[1], x[2] * y[0] - x[0] * y[2], x[0] * y[1] - x[1] * y[0])
			ret = Vector(ret)
			if n == 2:
				return ret
			else:
				return ret

class Segment:

	def __init__(self, v1, v2):
		self.v1 = v1
		self.v2 = v2

	def length(self):
		return norm(self.v1 - self.v2)

	def get_unit_vec(self):
		dist = norm(self.v2 - self.v1)
		if dist != 0:
			return (self.v2 - self.v1) / dist
		else:
			return False

	def projection(self, vector):
		unit_vec = self.get_unit_vec()
		t = unit_vec * (vector - self.v1)
		return self.v1 + t * unit_vec

	def is_vertical(self, other):
		return is_equal(0, self.get_unit_vec() * other.get_unit_vec())

	def is_horizontal(self, other):
		return is_equal(0, self.get_unit_vec() ** other.get_unit_vec())

	def reflection(self, vector):
		projection = self.projection(vector)
		v = projection - vector
		return projection + vector

	def include(self, vector):
		proj = self.projection(vector)
		if not is_equal(norm(proj - vector), 0):
			return False
		else:
			n = len(self.v1)
			f = True
			for i in range(n):
				f &= self.v1[i] <= vector[i] <= self.v2[i] or self.v2[i] <= vector[i] <= self.v1[i]
			return f

	def distance(self, other):
		if isinstance(other, Vector):
			proj = self.projection(other)
			if self.include(proj):
				return norm(proj - other)
			else:
				ret = []
				ret.append(norm(self.v1 - other))
				ret.append(norm(self.v2 - other))
				return min(ret)

	def ccw(self, vector):
		direction = self.v2 - self.v1
		v = vector - self.v1
		if self.include(vector):
			return 0
		else:
			cross = direction ** v
			if cross[2] <= 0:
				return 1
			else:
				return -1

	def intersect(self, segment):
		ccw12 = self.ccw(segment.v1)
		ccw13 = self.ccw(segment.v2)
		ccw20 = segment.ccw(self.v1)
		ccw21 = segment.ccw(self.v2)
		if ccw12 * ccw13 * ccw20 * ccw21 == 0:
			return True
		elif ccw12 * ccw13 < 0 and ccw20 * ccw21 < 0:
			return True
		else:
			return False

	def intersect_point(self, segment):
		d1 = norm(self.projection(segment.v1) - segment.v1)
		d2 = norm(self.projection(segment.v2) - segment.v2)
		return segment.v1 + d1 / (d1 + d2) * (segment.v2 - segment.v1)

class Line(Segment):

	def include(self, vector):
		proj = self.projection(vector)
		return is_equal(norm(proj - vector), 0)
q = int(input())
tmp = [0] * q
for i in range(q):
	tmp[i] = list(map(int, input().split()))
for i in range(q):
	(p0, p1, p2, p3) = (Vector(tmp[i][0:2]), Vector(tmp[i][2:4]), Vector(tmp[i][4:6]), Vector(tmp[i][6:8]))
	S1 = Segment(p0, p1)
	S2 = Segment(p2, p3)
	print(*S1.intersect_point(S2))


import sys
from sys import stdin
input = stdin.readline

class Point(object):
	epsilon = 1e-10

	def __init__(self, x=0.0, y=0.0):
		if isinstance(x, tuple):
			self.x = x[0]
			self.y = x[1]
		else:
			self.x = x
			self.y = y

	def __add__(self, other):
		return Point(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Point(self.x - other.x, self.y - other.y)

	def __mul__(self, other):
		return Point(other * self.x, other * self.y)

	def __truediv__(self, other):
		return Point(other / self.x, other / self.y)

	def __lt__(self, other):
		if self.x == other.x:
			return self.y < other.y
		else:
			return self.x < other.x

	def __eq__(self, other):
		from math import fabs
		if fabs(self.x - other.x) < Point.epsilon and fabs(self.y - other.y) < Point.epsilon:
			return True
		else:
			return False

	def norm(self):
		return self.x * self.x + self.y * self.y

	def abs(self):
		from math import sqrt
		return sqrt(self.norm())

class Vector(Point):

	def __init__(self, x=0.0, y=0.0):
		if isinstance(x, tuple):
			self.x = x[0]
			self.y = x[1]
		elif isinstance(x, Point):
			self.x = x.x
			self.y = x.y
		else:
			self.x = x
			self.y = y

	def __add__(self, other):
		return Vector(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Vector(self.x - other.x, self.y - other.y)

	def __mul__(self, other):
		return Vector(other * self.x, other * self.y)

	def __truediv__(self, other):
		return Vector(other / self.x, other / self.y)

	@classmethod
	def dot(cls, a, b):
		return a.x * b.x + a.y * b.y

	@classmethod
	def cross(cls, a, b):
		return a.x * b.y - a.y * b.x

	@classmethod
	def is_orthogonal(cls, a, b):
		return Vector.dot(a, b) == 0.0

	@classmethod
	def is_parallel(cls, a, b):
		return Vector.cross(a, b) == 0.0

class Segment(object):

	def __init__(self, p1=Point(), p2=Point()):
		if isinstance(p1, Point):
			self.p1 = p1
			self.p2 = p2
		elif isinstance(p1, tuple):
			self.p1 = Point(p1[0], p1[1])
			self.p2 = Point(p2[0], p2[1])

	@classmethod
	def is_orthogonal(cls, s1, s2):
		a = Vector(s1.p2 - s1.p1)
		b = Vector(s2.p2 - s2.p1)
		return Vector.is_orthogonal(a, b)

	@classmethod
	def is_parallel(cls, s1, s2):
		a = Vector(s1.p2 - s1.p1)
		b = Vector(s2.p2 - s2.p1)
		return Vector.is_parallel(a, b)

class Line(Segment):
	pass

class Cirle(object):

	def __init__(self, c=Point(), r=0.0):
		self.c = c
		self.r = r

def ccw(p0, p1, p2):
	a = Vector(p1 - p0)
	b = Vector(p2 - p0)
	epsilon = 1e-10
	if Vector.cross(a, b) > epsilon:
		return 1
	elif Vector.cross(a, b) < -epsilon:
		return -1
	elif Vector.dot(a, b) < -epsilon:
		return 2
	elif a.norm() < b.norm():
		return -2
	else:
		return 0

def cross_point(s1, s2):
	base = s2.p2 - s2.p1
	d1 = abs(Vector.cross(base, s1.p1 - s2.p1))
	d2 = abs(Vector.cross(base, s1.p2 - s2.p1))
	t = d1 / (d1 + d2)
	return s1.p1 + (s1.p2 - s1.p1) * t

def main(args):
	q = int(input())
	for _ in range(q):
		(x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3) = map(int, input().split())
		p0 = Point(x_p0, y_p0)
		p1 = Point(x_p1, y_p1)
		p2 = Point(x_p2, y_p2)
		p3 = Point(x_p3, y_p3)
		s1 = Segment(p0, p1)
		s2 = Segment(p2, p3)
		result = cross_point(s1, s2)
		print('{:.10f} {:.10f}'.format(result.x, result.y))
main(sys.argv[1:])


import math
EPS = 1e-10

def equals(a, b):
	return abs(a - b) < EPS

class Point:

	def __init__(self, x=0, y=0):
		self.x = x
		self.y = y

	def __add__(self, p):
		return Point(self.x + p.x, self.y + p.y)

	def __sub__(self, p):
		return Point(self.x - p.x, self.y - p.y)

	def __mul__(self, a):
		return Point(self.x * a, self.y * a)

	def __rmul__(self, a):
		return self * a

	def __truediv__(self, a):
		return Point(self.x / a, self.y / a)

	def norm(self):
		return self.x * self.x + self.y * self.y

	def abs(self):
		return math.sqrt(self.norm())

	def __lt__(self, p):
		if self.x != p.x:
			return self.x < p.x
		else:
			return self.y < p.y

	def __eq__(self, p):
		return equals(self.x, p.x) and equals(self.y, p.y)

class Segment:

	def __init__(self, p1, p2):
		self.p1 = p1
		self.p2 = p2

def dot(a, b):
	return a.x * b.x + a.y * b.y

def cross(a, b):
	return a.x * b.y - a.y * b.x

def getCrossPoint(s1, s2):
	base = s2.p2 - s2.p1
	d1 = abs(cross(base, s1.p1 - s2.p1))
	d2 = abs(cross(base, s1.p2 - s2.p1))
	t = d1 / (d1 + d2)
	return s1.p1 + (s1.p2 - s1.p1) * t
q = int(input())
ans = []
for i in range(q):
	(x0, y0, x1, y1, x2, y2, x3, y3) = [int(v) for v in input().split()]
	s1 = Segment(Point(x0, y0), Point(x1, y1))
	s2 = Segment(Point(x2, y2), Point(x3, y3))
	ans.append(getCrossPoint(s1, s2))
for v in ans:
	print('{0:.10f} {1:.10f}'.format(v.x, v.y))


q = int(input())
for i in range(q):
	(a, b, c, d, e, f, g, h) = [int(i) for i in input().split()]
	A = a * d - b * c
	B = e * h - f * g
	C = d - b
	D = c - a
	E = f - h
	F = e - g
	G = C * F - D * E
	print((A * F + B * D) / G, (A * E + B * C) / G)


from math import sqrt
q = int(input())

class Segment:
	pass

def add(a, b):
	return [a[0] + b[0], a[1] + b[1]]

def sub(a, b):
	return [a[0] - b[0], a[1] - b[1]]

def multi(k, a):
	return [k * a[0], k * a[1]]

def cross(a, b):
	return a[0] * b[1] - a[1] * b[0]

def norm(a):
	return sqrt(a[0] ** 2 + a[1] ** 2)
for i in range(q):
	(xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3) = map(int, input().split())
	s1 = Segment()
	s2 = Segment()
	s1.p1 = [xp0, yp0]
	s1.p2 = [xp1, yp1]
	s2.p1 = [xp2, yp2]
	s2.p2 = [xp3, yp3]
	base = sub(s2.p2, s2.p1)
	d1 = abs(cross(base, sub(s1.p1, s2.p1))) / norm(base)
	d2 = abs(cross(base, sub(s1.p2, s2.p1))) / norm(base)
	t = d1 / (d1 + d2)
	x = add(s1.p1, multi(t, sub(s1.p2, s1.p1)))
	print(x[0], x[1])


def intersection_ll(s0, s1, t0, t1):
	(x0, y0) = s0
	(x1, y1) = s1
	(X0, X1) = t0
	(X1, Y1) = t1
	p = (x1 - x0) * (y0 - Y0) - (y1 - y0) * (x0 - X0)
	q = (x1 - x0) * (Y1 - Y0) - (y1 - y0) * (X1 - X0)
	return (X0 + p * (X1 - X0) / float(q), Y0 + p * (Y1 - Y0) / float(q))
n = int(input())
for i in range(n):
	(x0, y0, x1, y1, X0, Y0, X1, Y1) = map(int, input().split())
	print('%.08f %.08f' % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1)))


from typing import List, Tuple
from math import sqrt
from enum import IntEnum
EPS = 1e-10

def float_equal(x: float, y: float) -> bool:
	return abs(x - y) < EPS

class PointLocation(IntEnum):
	COUNTER_CLOCKWISE = 1
	CCW = 1
	CLOCKWISE = -1
	CW = -1
	ONLINE_BACK = 2
	O_B = 2
	ONLINE_FRONT = -2
	O_F = -2
	ON_SEGMENT = 0
	O_S = 0
PL = PointLocation

class Point:

	def __init__(self, x: float=0.0, y: float=0.0) -> None:
		self.x = x
		self.y = y

	def __repr__(self) -> str:
		return 'Point({}, {})'.format(self.x, self.y)

	def __eq__(self, other: object) -> bool:
		if not isinstance(other, Point):
			return NotImplemented
		return float_equal(self.x, other.x) and float_equal(self.y, other.y)

	def __add__(self, other: 'Point') -> 'Point':
		return Point(self.x + other.x, self.y + other.y)

	def __sub__(self, other: 'Point') -> 'Point':
		return Point(self.x - other.x, self.y - other.y)

	def __mul__(self, k: float) -> 'Point':
		return Point(self.x * k, self.y * k)

	def __rmul__(self, k: float) -> 'Point':
		return self * k

	def __truediv__(self, k: float) -> 'Point':
		return Point(self.x / k, self.y / k)

	def __lt__(self, other: 'Point') -> bool:
		return self.y < other.y if abs(self.x - other.x) < EPS else self.x < other.x

	def norm(self):
		return self.x * self.x + self.y * self.y

	def abs(self):
		return sqrt(self.norm())

	def dot(self, other: 'Point') -> float:
		return self.x * other.x + self.y * other.y

	def cross(self, other: 'Point') -> float:
		return self.x * other.y - self.y * other.x

	def is_orthogonal(self, other: 'Point') -> bool:
		return float_equal(self.dot(other), 0.0)

	def is_parallel(self, other: 'Point') -> bool:
		return float_equal(self.cross(other), 0.0)

	def distance(self, other: 'Point') -> float:
		return (self - other).abs()

	def in_side_of(self, seg: 'Segment') -> bool:
		return seg.vector().dot(Segment(seg.p1, self).vector()) >= 0

	def in_width_of(self, seg: 'Segment') -> bool:
		return self.in_side_of(seg) and self.in_side_of(seg.reverse())

	def distance_to_line(self, seg: 'Segment') -> float:
		return abs((self - seg.p1).cross(seg.vector())) / seg.length()

	def distance_to_segment(self, seg: 'Segment') -> float:
		if not self.in_side_of(seg):
			return self.distance(seg.p1)
		if not self.in_side_of(seg.reverse()):
			return self.distance(seg.p2)
		else:
			return self.distance_to_line(seg)

	def location(self, seg: 'Segment') -> PointLocation:
		p = self - seg.p1
		d = seg.vector().cross(p)
		if d > EPS:
			return PointLocation.COUNTER_CLOCKWISE
		if d < -EPS:
			return PointLocation.CLOCKWISE
		if seg.vector().dot(p) < 0.0:
			return PointLocation.ONLINE_BACK
		if seg.vector().norm() < p.norm():
			return PointLocation.ONLINE_FRONT
		return PointLocation.ON_SEGMENT
Vector = Point

class Segment:

	def __init__(self, p1: Point=None, p2: Point=None) -> None:
		self.p1: Point = Point() if p1 is None else p1
		self.p2: Point = Point() if p2 is None else p2

	def __repr__(self) -> str:
		return 'Segment({}, {})'.format(self.p1, self.p2)

	def __eq__(self, other: object) -> bool:
		if not isinstance(other, Segment):
			return NotImplemented
		return self.p1 == other.p1 and self.p2 == other.p2

	def vector(self) -> Vector:
		return self.p2 - self.p1

	def reverse(self) -> 'Segment':
		return Segment(self.p2, self.p1)

	def length(self) -> float:
		return self.p1.distance(self.p2)

	def is_orthogonal(self, other: 'Segment') -> bool:
		return self.vector().is_orthogonal(other.vector())

	def is_parallel(self, other: 'Segment') -> bool:
		return self.vector().is_parallel(other.vector())

	def projection(self, p: Point) -> Point:
		v = self.vector()
		vp = p - self.p1
		return v.dot(vp) / v.norm() * v + self.p1

	def reflection(self, p: Point) -> Point:
		x = self.projection(p)
		return p + 2 * (x - p)

	def intersects(self, other: 'Segment') -> bool:
		d0: PointLocation = self.p1.location(other)
		d1: PointLocation = self.p2.location(other)
		d2: PointLocation = other.p1.location(self)
		d3: PointLocation = other.p2.location(self)
		return d0 * d1 * d2 * d3 == 0 or (d0 * d1 == -1 and d2 * d3 == -1)

	def intersection(self, other: 'Segment') -> Point:
		a = self.vector()
		b = other.vector()
		c = self.p1 - other.p1
		s = b.cross(c) / a.cross(b)
		return self.p1 + s * a

	def distance_with_segment(self, other: 'Segment') -> float:
		if not self.is_parallel(other) and self.intersects(other):
			return 0
		else:
			return min(self.p1.distance_to_segment(other), self.p2.distance_to_segment(other), other.p1.distance_to_segment(self), other.p2.distance_to_segment(self))
Line = Segment

class Circle:

	def __init__(self, c: Point=None, r: float=0.0) -> None:
		self.c: Point = Point() if c is None else c
		self.r: float = r

	def __eq__(self, other: object) -> bool:
		if not isinstance(other, Circle):
			return NotImplemented
		return self.c == other.c and self.r == other.r

	def __repr__(self) -> str:
		return 'Circle({}, {})'.format(self.c, self.r)

def main() -> None:
	q = int(input())
	for _ in range(q):
		(x0, y0, x1, y1, x2, y2, x3, y3) = [int(x) for x in input().split()]
		s1 = Segment(Point(x0, y0), Point(x1, y1))
		s2 = Segment(Point(x2, y2), Point(x3, y3))
		p = s1.intersection(s2)
		print(p.x, p.y)
main()


q = int(input())
for i in range(q):
	(a, b, c, d, e, f, g, h) = [int(i) for i in input().split()]
	A = a * d - b * c
	B = e * h - f * g
	C = d - b
	D = c - a
	E = f - h
	F = e - g
	det = C * F - D * E
	print((A * F + B * D) / det, (A * E + B * C) / det)


class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

class Segment:

	def __init__(self, x1, y1, x2, y2):
		self.p1 = Point(x1, y1)
		self.p2 = Point(x2, y2)
		if self.p1.x == self.p2.x:
			self.a = float('inf')
			self.b = None
		else:
			self.a = (self.p1.y - self.p2.y) / (self.p1.x - self.p2.x)
			self.b = self.p1.y - self.a * self.p1.x

	def is_intersect(self, seg):
		a = (seg.p1.x - seg.p2.x) * (self.p1.y - seg.p1.y) + (seg.p1.y - seg.p2.y) * (seg.p1.x - self.p1.x)
		b = (seg.p1.x - seg.p2.x) * (self.p2.y - seg.p1.y) + (seg.p1.y - seg.p2.y) * (seg.p1.x - self.p2.x)
		c = (self.p1.x - self.p2.x) * (seg.p1.y - self.p1.y) + (self.p1.y - self.p2.y) * (self.p1.x - seg.p1.x)
		d = (self.p1.x - self.p2.x) * (seg.p2.y - self.p1.y) + (self.p1.y - self.p2.y) * (self.p1.x - seg.p2.x)
		e = (self.p1.x - seg.p1.x) * (self.p2.x - seg.p2.x)
		f = (self.p1.x - seg.p2.x) * (self.p2.x - seg.p1.x)
		g = (self.p1.y - seg.p1.y) * (self.p2.y - seg.p2.y)
		h = (self.p1.y - seg.p2.y) * (self.p2.y - seg.p1.y)
		return a * b <= 0 and c * d <= 0 and (e <= 0 or f <= 0) and (g <= 0 or h <= 0)

	def cross_point(self, seg):
		if self.is_intersect(seg) == False:
			return None
		if self.a == float('inf'):
			return (self.p1.x, seg.a * self.p1.x + seg.b)
		elif seg.a == float('inf'):
			return (seg.p1.x, self.a * seg.p1.x + self.b)
		else:
			x = -(self.b - seg.b) / (self.a - seg.a)
			y = seg.a * x + seg.b
			return (x, y)
q = int(input())
for i in range(q):
	(x0, y0, x1, y1, x2, y2, x3, y3) = list(map(int, input().split(' ')))
	(line1, line2) = (Segment(x0, y0, x1, y1), Segment(x2, y2, x3, y3))
	(x, y) = line1.cross_point(line2)
	print('%.8f %.8f' % (x, y))


import math

class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __add__(self, other):
		return Point(self.x + other.x, self.y + other.y)

	def __sub__(self, other):
		return Point(self.x - other.x, self.y - other.y)

	def __mul__(self, other):
		return Point(self.x * other, self.y * other)

	def __floordiv__(self, other):
		return Point(self.x / other, self.y / other)

	def __repr__(self):
		return str(self.x) + ' ' + str(self.y)

class Vector(Point):
	pass

class Line:

	def __init__(self, p1, p2):
		self.p1 = p1
		self.p2 = p2

class Segment(Line):
	pass

def points_to_vector(p1, p2):
	x = p1.x - p2.x
	y = p1.y - p2.y
	return Vector(x, y)

def vector(p):
	return Vector(p.x, p.y)

def dot(v1, v2):
	return v1.x * v2.x + v1.y * v2.y

def cross(v1, v2):
	return v1.x * v2.y - v1.y * v2.x

def norm(v):
	return v.x ** 2 + v.y ** 2

def distance(v):
	return math.sqrt(norm(v))

def project(s, p):
	base = points_to_vector(s.p1, s.p2)
	hypo = points_to_vector(p, s.p1)
	r = dot(hypo, base) / norm(base)
	return s.p1 + base * r

def reflect(s, p):
	return p + (project(s, p) - p) * 2

def get_distance(s1, s2):
	if intersect_s(s1, s2):
		return 0
	d1 = get_distance_sp(s1, s2.p1)
	d2 = get_distance_sp(s1, s2.p2)
	d3 = get_distance_sp(s2, s1.p1)
	d4 = get_distance_sp(s2, s1.p2)
	return min(d1, min(d2, min(d3, d4)))

def get_distance_pp(p1, p2):
	return distance(p1 - p2)

def get_distance_lp(l, p):
	return abs(cross(l.p2 - l.p1, p - l.p1) / distance(l.p2 - l.p1))

def get_distance_sp(s, p):
	if dot(s.p2 - s.p1, p - s.p1) < 0:
		return distance(p - s.p1)
	elif dot(s.p1 - s.p2, p - s.p2) < 0:
		return distance(p - s.p2)
	else:
		return get_distance_lp(s, p)

def ccw(p0, p1, p2):
	EPS = 1e-10
	COUNTER_CLOCKWISE = 1
	CLOCKWISE = -1
	ONLINE_BACK = 2
	ONLINE_FRONT = -2
	ON_SEGMENT = 0
	v1 = p1 - p0
	v2 = p2 - p0
	if cross(v1, v2) > EPS:
		return COUNTER_CLOCKWISE
	elif cross(v1, v2) < -EPS:
		return CLOCKWISE
	elif dot(v1, v2) < -EPS:
		return ONLINE_BACK
	elif norm(v1) < norm(v2):
		return ONLINE_FRONT
	else:
		return ON_SEGMENT

def intersect_p(p1, p2, p3, p4):
	return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0

def intersect_s(s1, s2):
	return intersect_p(s1.p1, s1.p2, s2.p1, s2.p2)

def get_cross_point(s1, s2):
	base = s2.p2 - s2.p1
	d1 = abs(cross(base, s1.p1 - s2.p1))
	d2 = abs(cross(base, s1.p2 - s2.p1))
	t = d1 / (d1 + d2)
	return s1.p1 + (s1.p2 - s1.p1) * t
import sys
q = int(input())
for i in range(q):
	temp = list(map(int, input().split()))
	points = []
	for j in range(0, 8, 2):
		points.append(Point(temp[j], temp[j + 1]))
	s1 = Segment(points[0], points[1])
	s2 = Segment(points[2], points[3])
	print(get_cross_point(s1, s2))


n = int(input())

def cross(a, b):
	return a[0] * b[1] - a[1] * b[0]

def length(vector):
	ans = 0
	for i in vector:
		ans += i ** 2
	return ans ** (1 / 2)

def dot(a, b):
	n = len(a)
	if n != len(b):
		return None
	ans = 0
	for (i, j) in zip(a, b):
		ans += i * j
	return ans
for i in range(n):
	(a, b, c, d, e, f, g, h) = list(map(int, input().split()))
	s1 = (c - a, d - b)
	s2 = (g - e, h - f)
	d1 = abs(cross(s1, (e - a, f - b))) / length(s1)
	d2 = abs(cross(s1, (g - a, h - b))) / length(s1)
	t = d1 / (d1 + d2)
	ans = (e * (1 - t) + g * t, f * (1 - t) + h * t)
	print(f'{ans[0]:.8f} {ans[1]:.8f}')