# cook your dish here
for _ in range(int(input())):
    count=0
    n,m=map(int,input().split())
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    a_set = set(a) 
    b_set = set(b) 
  
    if (a_set & b_set): 
        count+=1
        
    else: 
        print("NO")
    
    lst3 = [value for value in a if value in b] 
    if len(lst3)>1:
        print("YES")
        print("1",lst3[0])
    elif len(lst3)==1:
        print("YES")
        print(len(lst3),*lst3)