for t in range(int(input())):
    n,m = map(int, input().split())
    A = set(map(int, input().split()))
    B = set(map(int, input().split()))

    A.intersection_update(B)
    # print(A)

    if len(A)>=1:
        x = A.pop()
        print("YES")
        print(1,x)
    else:
        print("NO")