t=int(input())
for g in range(t):
        n,m=map(int,input().split())
        l=list(map(int,input().split()))
        p=list(map(int,input().split()))
        c=0
        for i in l:
                if i in p:
                        print("YES")
                        print("1 "+str(i))
                        c=1
                        break
        if c==0:
                print("NO")