for tc in range(int(input())):
	n,m=map(int,input().split())
	a=list(map(int,input().split()))
	b=list(map(int,input().split()))
    
	if not set(a)&set(b):
		print("NO")
	else:
		for i in a:
			if b.count(i):
				print("YES")
				print(1,i)
				break