# dic = {4:5,2:2,1:8,3:4,5:1}
# dic = sorted(dic,key = dic.keys())
# print(dic)

# print((2|3|32|43|8)|(43), 2|32|8)
# print(2|3|32|43|8, 3|43, 32|8, 43, 8)
for _ in range(int(input())):
	n,m = map(int,input().split())
	a = list(map(int,input().split()))
	b = list(map(int,input().split()))
	x = -1
	for i in range(n):
		for j in range(m):
			if a[i]==b[j]:
				x = a[i]
				break
		if x>-1:
			break
	if x>-1:
		print('YES')
		print(1, x)
	else:
		print('NO')