def f(a,b):
 u=set(a)&set(b)
 if u: return list(u)[0]
 else: return False

for t in xrange(int(raw_input())):
 n,m=map(int,raw_input().split())
 a=map(int,raw_input().split())
 b=map(int,raw_input().split())
 t=f(a,b)
 if t is False: print 'NO'
 else: print 'YES'; print '1 '+str(t)
