for i in range(int(input())):
    n,m=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    c=0
    for j in range(n):
        for i in range(m):
            if l2[i]==l1[j]:
                c+=1
                if c>1:
                    break
                else:
                  print("YES")
                  print(1,end=" ")
                  print(l2[i])
            
    if c==0:
        print("NO")
    
                
