t=input()
for i in range(int(t)):
    n,m = map(int, input().split())

    a = [int(aa) for aa in input().split()]
    b = [int(aa) for aa in input().split()]
    f=0
    ans=0
    for i in a:
        if i in b:
            f=1
            ans=i
            break
    if f==1:
        print("YES")
        print("1 %d"%(ans))
    else:
        print("NO")
