for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    c=list(map(int,input().split()))
    b={}
    r=[]
    for i in a:
        if i in b:
            b[i]+=1
        else:
            b[i]=1
    for i in c:
        if i in b:
            r.append(i)
            break
    if len(r)==0:
        print('NO')
    else:
        print('YES')
        print(1,r[0])

