for t in range(int(input())):
    n1,n2=map(int,(input().split()))
    l1=set(map(int,(input().split())))
    l2=set(map(int,(input().split())))
    if l1.intersection(l2):
        print("YES")
        print("1 "+str(list(l1.intersection(l2))[0]))
    else:
        print("NO")