t = int(input())
for i in range(t):
	n, m = map(int, input().split())
	a = sorted(map(int, input().split()))
	b = sorted(map(int, input().split()))
	result = 0
	for i in range(n):
		for j in range(m):
			if a[i] == b[j]:
				result = a[i]
	print("YES\n"+"1 "+str(result)) if result!=0 else print("NO")