t = int(input())
for i in range(t):
    n,m=(map(int,input().split()))
    l=list(map(int,input().split()))
    r=list(map(int,input().split()))
    ans=-1
    for i in range(n):
        if l[i] in r:
            ans=l[i]
            break
    if ans==-1:
        print("NO")
    else:
        print("YES")
        print(1,ans)
    