
for _ in range(int(input())):
	n,m = map(int,input().split())
	x = list(map(int,input().split()))
	y = list(map(int,input().split()))
	f= False
	for i in x:
		if i in y:
			print("YES")
			print(1,i)
			f=True
			break
	if not f:
		print("NO")

