for _ in range(int(input())):
    m,n=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    
    d={}
    
    for i in l1:
        d[i]=1
    for i in l2:
        if i in d:
            print("YES")
            print(1, i)
            break
    else:
        print("NO")
        
    