T=int(input())
for i in range(T):
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    flag=0
    ans=0
    for i in range(n):
        for j in range(m):
            if a[i]==b[j]:
                flag=1
                ans=a[i]
                break
        if flag==1:
            break
    if flag==0:
        print("NO")
    else:
        print("YES")
        print(1,ans)
        
