for _ in range(int(input())):
    n,m=map(int,input('').split())
    A=list(map(int,input('').split()))
    B=list(map(int,input('').split()))
    count=dict()
    for i in A:
        count[i]=True
    flag=0
    for i in B:
        if i in count.keys():
            flag=1
            break
    if flag==1:
        print("YES")
        print(1,i)
    else:
        print("NO")
