t= int(input())
ans=[]
for i in range(t):
    q=1
    n,m= [int(i) for i in input().split()]
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    for i in a:
        if i in b:
            q=0
            ans.append("YES")
            ans.append((1,i))
            break
    if q==1:
        ans.append("NO")

for i in ans:
    if type(i)!=str:
        print(*i)
    else:
        print(i)