tc = int(input())
for _ in range(tc):
	[leng1, leng2] = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr1_as_set = set(arr1)
	intersection = list (arr1_as_set.intersection(arr2))
	if(intersection):
		print("YES")
		print(1, intersection[0])
	else:
		print("NO")