t = int(raw_input())
while t > 0:
	t -= 1
	n, m = map(int, raw_input().split())
	d1 = map(int, raw_input().split())
	d2 = map(int, raw_input().split())
	s = set(d1) & set(d2)
	if len(s) == 0:
		print 'NO'
	else:
		print 'YES'
		print '1 %s' % list(s)[0]