for _ in range(int(input())):
    n,m=map(int,input().split())
    list1=list(map(int,input().split()))
    list2=list(map(int,input().split()))
    set1=set(list1)
    set2=set(list2)
    set3=set1.intersection(set2)
    #print(set3)
    if len(set3)>0:
        print("YES")
        print(1,end=" ")
        for i in set3:
            print(i)
            break
    else:
        print("NO")