for _ in range(int(input())):
	(x,y)=map(int,input().split())
	a=list(map(int,input().split()))
	b=list(map(int,input().split()))
	t=0
	for i in range(len(a)):
		if a[i] in b:
			t=1
			print('YES')
			print(1,a[i])
			break
	if t==0:
		print('NO')