t = int(input())

while (t):
	
	line = input().split()
	n,m = int(line[0]), int(line[1])

	a = input().split()
	a = list(map(int,a))

	b = input().split()
	b = set(list(map(int,b)))

	ans = -1
	for x in a:	
		if (x in b):
			ans = x
			break

	if (ans == -1):
		print('NO')
	else:
		print('YES')
		print(1,ans)

	t -= 1
