for _ in range(int(raw_input())):
    m,n=list(map(int,raw_input().split()))
    marr=list(map(int,raw_input().split()))
    narr=list(map(int,raw_input().split()))
    mdic=[0]*1001
    for i in marr:
        mdic[i]=1
    flag=True   
    for i in narr:
        if mdic[i]:
            print("YES")
            print 1,i
            flag=False
            break
    if flag:
        print("NO")