for _ in xrange(int(raw_input())):
    n, m = map(int, raw_input().split())
    a = set(map(int, raw_input().split()))
    b = set(map(int, raw_input().split()))
    c = a & b
    if len(c):
        print "YES"
        print 1,
        print sorted(c)[0]
    else:
        print "NO"