n = int(input())
for i in range(n):
    n1,n2 = input().split(" ")
    arr1 = input().split(" ")
    arr2 = input().split(" ")
    out=[]
    for item in arr1:
        if(item in arr2):
            out.append(item)
    if(len(out)>0):
        print("YES")
        print("1",out[0],end=" ")
        #[print(x,end=" ") for x in out]
        print()

    else:
        print("NO")
        
    
