t=int(input())
def fun(n,a,b):
    ans=0
    for i in range(n):
        if b.count(a[i])!=0:
            ans=a[i]
            break
    if ans==0:
        print("NO")
    else:
        print("YES")
        print(1,ans)
while t:
    t-=1
    n,m=map(int,input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    fun(n,a,b)
