t=int(input())
for _ in range(t):
    n,m=[int(x) for x in input().split()]
    a=[int(x) for x in input().split()]
    b=[int(x) for x in input().split()]
    a.sort()
    b.sort()
    c=0
    ans=0
    for i in range(len(b)):
        if b[i] in a:
            c=1
            ans=b[i]
            break
    if c==1:
        print("YES")
        print(1,ans)
    else:
        print("NO")
            
