t=int(input())
for T in range(t):
    n,m=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    c=0
    l3=[]
    for i in range(len(l1)):
        if l1[i] in l2:
            print("YES")
            c+=1
            l3.append(l1[i])
            break
    if c==0:
        print("NO")
    else:
        print(1,*l3)
