t=int(input())
for _ in range(t):
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    a.sort()
    b.sort()
    ans=0
    i=0
    j=0
    while i<n and j<m:
        if a[i]==b[j]:
            ans=a[i]
            break
        elif a[i]<b[j]:
            i=i+1
        elif a[i]>b[j]:
            j=j+1
    if ans:
        print('YES')
        print(1,ans)
    else:
        print('NO')