t=int(input())
f=[]
for i in range(t):
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    a=list(set(a))
    b=list(set(b))
    if(n<m):
        temp=a
        a=b
        b=temp
    for j in range(len(a)):
        if(a[j] in b):
            f.append("YES\n1 "+str(a[j]))
            break
    else:
        f.append("NO")
print(*f,sep="\n")
        
        
    
   
            
        
        
        