c = int(input())
while c:
    c -= 1
    n, m = input().split()

    set1 = set(map(int, input().split()))
    set2 = set(map(int, input().split()))

    x = set1.intersection(set2)

    if x == set():
        print("NO")
    else:
        print("YES")
        print(1, list(x)[0])