def find_seq(a,b):
	var = 0
	for i in a:
		if i in b:
			var = 1
			k = i
			break
		if var==1:
			break
	if var==0:
		print('NO')
	else:
		print('YES')
		print(1 , k)

t = int(input())
for _ in range(t):
	n,m = map(int,input().split())
	a = list(map(int,input().split()))
	b = list(map(int,input().split()))
	find_seq(a,b)