t=int(input())

while t:
    t-=1
    n,m=input().split(" ")
    a=[]
    b=[]
    c=[]
    a=[int(i) for i in input().split(" ")]
    b=[int(i) for i in input().split(" ")]
    
    for i in a:
        if (i in b):
            c.append(i)
    
    if len(c)==0:
        print("NO")
    else:
        print("YES")
        #print(len(c)," ".join(str(x) for x in c))
        print("1",c[0])
            
            


    