def common(a,b): 
    c = [value for value in a if value in b] 
    return c

T=int(input())
for i in range(T):
    n,m=map(int,input().split())
    lst1=list(map(int,input().split()))
    lst2=list(map(int,input().split()))
    d=[]
    d=common(lst1,lst2)
    if len(d)==0:
        print("NO")
    else:
        print("YES")
        print(1,d[0],sep=" ")
    
    
    
    
    
    
    
    