t = int(input())

def solve(a, b):
	for i in a:
		for j in b:
			if(i == j):
				print("YES")
				print(1, i)
				return
	print("NO")

for _ in range(t):
	n,m = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]

	solve(a, b)