import sys
input = sys.stdin.buffer.readline
def I(): return(list(map(int,input().split())))
def sieve(n):
	a=[1]*n
	for i in range(2,n):
	    if a[i]:
	        for j in range(i*i,n,i):
	            a[j]=0
	return a

for __ in range(int(input())):
	n,m = I()
	a = set(I())
	b = set(I())
	c =a.intersection(b)
	if c:
		print("YES")
		for i in c:
			print(1,i)
			break
	else:
		print("NO")