for _ in range(int(input())):
	a, b = map(int, input().split())
	ls = list(map(int, input().split()))
	lm = list(map(int, input().split()))
	f = False
	for i in range(a):
		for j in range(b):
			if ls[i] == lm[j]:
				print('YES')
				print(1, ls[i])
				f = True
				break
		if f:
			break
	if not f:
		print('NO')

