t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ans=0
    yep=False
    for i in range(len(a)):
        if a[i] in b:
            ans=a[i]
            yep=True
            break
    if yep:
        print("YES")
        print(1,a[i])
    else:
        print("NO")