from sys import stdin
t = int(stdin.readline())
for _ in xrange(t):
    n,m = map(int,stdin.readline().split())
    a = map(int,stdin.readline().split())
    b = map(int,stdin.readline().split())
    a = set(a)
    b = set(b)
    a = a & b
    if len(a):
        print "YES"
        print 1,list(a)[0]
    else:
        print "NO"