

t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    a=[int(x) for x in input().split()]
    b=[int(x) for x in input().split()]

    a=sorted(a)
    b=sorted(b)

    i=0
    j=0
    flag=False
    while (i<n and j<m):
        if a[i]==b[j]:
            flag=True
            print("YES")
            print(1,b[j])
            break
        elif a[i]<b[j]:
            i=i+1
        else:
            j=j+1    
    if flag:
        pass
    else:
        print("NO")
