t=int(input())
for i in range(t):
    n,m=[int(j) for j in input().split()]
    a=[int(j) for j in input().split()]
    b=[int(j) for j in input().split()]
    a.sort()
    b.sort()
    i=0
    j=0
    flag=False
    while i<n and j<m:
        if a[i]<b[j]:
            i+=1
        elif a[i]>b[j]:
            j+=1
        else:
            flag=True
            print("YES")
            print("1",a[i])
            break
    if not flag:
        print("NO")