import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n,m = MI()
	a = LI()
	b = LI()
	ans = 0
	boo = False
	for i in range(n):
		for j in range(m):
			if a[i] == b[j]:
				ans = a[i]
				boo = True
				break
		if boo:
			break
	if boo:
		print("YES")
		print(1,ans)
	else:
		print("NO")
