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

    def solve(arr,brr,n,m):
        comm=0
        for i in arr:
            if i not in brr:
                comm+=1
            else:
                print "YES"
                print 1,i
                break

        if comm==len(arr):
            print "NO"
    solve(arr,brr,n,m)