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