t=int(input())
while(t):
    m,n=map(int,input().split())
    a=[]
    b=[]
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    f=0
    for i in range(m):
        if a[i] in b:
            f=0
            break
        else:
            f=1
    if f==0:
        print("YES")
        print(1,a[i])
    else:
        print("NO")
                


    
    t-=1
    
