# your code goes here
def work(l1,l2):
	for i in l1:
		if i in l2:
			return i
	return 0
	
	
t = int(input())
for i in range(t):
	n1,n2 = map(int,input().split())
	l1 = list(map(int,input().split()))
	l2 = list(map(int,input().split()))
	x = work(l1,l2)
	if x==0:
		print("NO")
	else:
		print("YES")
		print("1",x,sep=" ")