t=int(input())
i=0
while i<t:
    x,y=[int(x) for x in input().split()]
    #print(x,y)
    a=set([int(x) for x in input().split()])
    b=set([int(x) for x in input().split()])
    common=list(a.intersection(b))
    l_common=len(common)
    if l_common>0:
        print("YES")
        print("1",common[0])
    else:
        print("NO")



    i+=1