for t in range(eval(input())):

    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split()))

    dx0 = x1 - x0

    dy0 = y1 - y0

    dx1 = x3 - x2

    dy1 = y3 - y2



    s = (y0-y2)*dx1 - (x0-x2)*dy1

    sm = dx0*dy1 - dy0*dx1

    if s < 0:

        s = -s

        sm = -sm

    t = (y2-y0)*dx0 - (x2-x0)*dy0

    tm = dx1*dy0 - dy1*dx0

    if t < 0:

        t = -t

        tm = -tm

    if s == 0:

        x = x0

        y = y0

    else:

        x = x0 + s*dx0/float(sm)

        y = y0 + s*dy0/float(sm)

    print("%.09f %.09f" % (x, y))
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) # -cross(S0, S1, T0)

    q = (x1-x0)*(Y1-Y0) - (y1-y0)*(X1-X0) # cross(0, S1-S0, T1-T0)

    return (X0 + p*(X1-X0)/float(q), Y0 + p*(Y1-Y0)/float(q))# T0 + p/q*(T1-T0)



n = int(eval(input()))

for i in range(n):

    x0, y0, x1, y1, X0, Y0, X1, Y1 = list(map(int, input().split()))

    print(("%.08f %.08f" % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1))))
for t in range(eval(input())):
    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split()))
    dx0 = x1 - x0
    dy0 = y1 - y0
    dx1 = x3 - x2
    dy1 = y3 - y2
    s = (y0 - y2) * dx1 - (x0 - x2) * dy1
    sm = dx0 * dy1 - dy0 * dx1
    if s < 0:
        s = -s
        sm = -sm
    t = (y2 - y0) * dx0 - (x2 - x0) * dy0
    tm = dx1 * dy0 - dy1 * dx0
    if t < 0:
        t = -t
        tm = -tm
    if s == 0:
        x = x0
        y = y0
    else:
        x = x0 + s * dx0 / float(sm)
        y = y0 + s * dy0 / float(sm)
    print("%.09f %.09f" % (x, y))

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)  # -cross(S0, S1, T0)
    q = (x1 - x0) * (Y1 - Y0) - (y1 - y0) * (X1 - X0)  # cross(0, S1-S0, T1-T0)
    return (
        X0 + p * (X1 - X0) / float(q),
        Y0 + p * (Y1 - Y0) / float(q),
    )  # T0 + p/q*(T1-T0)


n = int(eval(input()))
for i in range(n):
    x0, y0, x1, y1, X0, Y0, X1, Y1 = list(map(int, input().split()))
    print(("%.08f %.08f" % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1))))

-for t in range(eval(input())): -    x0, y0, x1, y1, x2, y2, x3, y3 = list(map(int, input().split())) -    dx0 = x1 - x0 -    dy0 = y1 - y0 -    dx1 = x3 - x2 -    dy1 = y3 - y2 -    s = (y0 - y2) * dx1 - (x0 - x2) * dy1 -    sm = dx0 * dy1 - dy0 * dx1 -    if s < 0: -        s = -s -        sm = -sm -    t = (y2 - y0) * dx0 - (x2 - x0) * dy0 -    tm = dx1 * dy0 - dy1 * dx0 -    if t < 0: -        t = -t -        tm = -tm -    if s == 0: -        x = x0 -        y = y0 -    else: -        x = x0 + s * dx0 / float(sm) -        y = y0 + s * dy0 / float(sm) -    print("%.09f %.09f" % (x, y)) +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)  # -cross(S0, S1, T0) +    q = (x1 - x0) * (Y1 - Y0) - (y1 - y0) * (X1 - X0)  # cross(0, S1-S0, T1-T0) +    return ( +        X0 + p * (X1 - X0) / float(q), +        Y0 + p * (Y1 - Y0) / float(q), +    )  # T0 + p/q*(T1-T0) + + +n = int(eval(input())) +for i in range(n): +    x0, y0, x1, y1, X0, Y0, X1, Y1 = list(map(int, input().split())) +    print(("%.08f %.08f" % intersection_ll((x0, y0), (x1, y1), (X0, Y0), (X1, Y1))))