for _ in range(int(input())):
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    p=list(map(int,input().split()))
    s=[]
    for i in l:
        if i in p:
            s.append(i)
            break
    if len(s):
        print("YES")
        print(1,end=' ')
        for i in s:
            print(i,end=' ')
        print()
    else:
        print("NO")