def solve():
    n = int(input())
    names = [input().split() for _ in range(n)]

    byFirst = set()
    bySecond = set()

    for i in range(n - 1, 0, -1):
        x, y = names[i]
        px, py = names[i - 1]

        if x != px and y != py and (px in byFirst or py in bySecond):
            print("No")
            break

        byFirst.add(x)
        bySecond.add(y)
    else:
        print("Yes")

t = int(input())

for _ in range(t):
    solve()
