t=int(raw_input())
for r in range(t):
    n,m= map(int, raw_input().split(" "))
    a= map(int, raw_input().split(" "))
    b= map(int, raw_input().split(" "))
    a.sort()
    b.sort()
    flag=0
    i=0
    j=0
    
    while(i<n and j<m):
        if a[i]==b[j]:
            flag=1
            print "YES"
            print "1",a[i]
            break
        elif a[i]<b[j]:
            i+=1
        else:
            j+=1
    if flag==0:
        print "NO"
    
            
            
            
            
    
