# from debug import debug
import sys
inf = int(1e10)
# sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline

t = int(input())
while t:
	t-=1
	g = 0
	n,m = map(int, input().split())
	lis = list(map(int,  input().split()))
	lis2 = list(map(int,  input().split()))
	for i in lis:
		for j in lis2:
			if i == j:
				g = 1
				print("YES")
				print(1, i)
				break
		if g:
			break
	if not g:
		print("NO")

