tc = int(input())

while tc:
	n, m = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	
	ans = -1
	
	for v in a:
		if v in b:
			ans = v;
			break;
	
	if ans==-1:
		print("NO")
	else:
		print("YES")
		print(1,'',ans)
	
	tc-=1
