
t=int(input())

for i in range(t):
    ch=input()
    L=[int(i)for i in ch.split()]
    n,m=L[0],L[1]
    ch=input()
    L1=[int(i)for i in ch.split()]
    ch=input()
    L2=[int(i)for i in ch.split()]
    test=False
    s=set()
    for i in range(n):
        s.add(L1[i])
    for i in range(m):
        if L2[i] in s:
            test=True
            print("YES")
            print(1,L2[i])
            break
    if test==False:
        print("NO")
