def intersection(lst1, lst2): 
    return list(set(lst1) & set(lst2)) 
  
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()))
    x=intersection(lst1, lst2)
    if len(x)==0:
        print("NO")
    else:
        print("YES")
        print("1",x[0])
        
#print(x)