from math import *
 
sInt = lambda: int(input())
mInt = lambda: map(int, input().split())
lInt = lambda: list(map(int, input().split()))
 
t = sInt()
 
for _ in range(t):
	n,m = mInt()
	a = lInt()
	b = lInt()
	ans = 0
	if a>b:
		a,b = b,a
	for i in a:
		if i in b:
			ans = i
			break
	if ans == 0:
		print("NO")
	else:
		print("YES")
		print(1, ans)