t = int(input())
for tests in range(t):
	n, m = map(int, input().split())
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	member = []
	for x in a.intersection(b):
		member = x
		break
	if member != []:
		print('YES')
		print('1 {}'.format(x))
	else:
		print('NO')
