for _ in range(int(input())):
    m,n=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    flag=0
    d={}
    l=[]
    for i in range(m):
        if a[i] in b:
            flag=1
            c=a[i]
            break
                
    if flag==0:
        print("NO")
    else:
        print("YES")
        print(1,a[i])
            
        