for t in range(input()):
    n,m=map(int,raw_input().split())
    a=map(int,raw_input().split())
    b=map(int,raw_input().split())
    flag=0
    ans=-1
    for i in a:
        for j in b:
            if i==j:
                flag=1
                ans=i
                break
    if flag==0:
        print "NO"
    else:
        print "YES"
        print 1,ans