t=int(input())
for _ in range(t):
    m,n=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    d=dict()
    for i in a:
        if i not in d:
            d[i]=1
        else:
            d[i]+=1
    
    flag=0
    for i in range(n):
        val=b[i]
        if val in d:
            flag=1
            ans=val
            break
        
    if flag==1:
        print('YES')
        print(1,ans)
    else:
        print('NO')