from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda:list(map(int, cin().split()))

t, = mp()
for _ in range(t):
	n, m = mp()
	a = mp()
	b = mp()
	
	l1 = [0]* 10001
	l2 = [0]* 10001
	
	for i in range(n):
		l1[a[i]] = 1
	for i in range(m):
		l2[b[i]] = 1
		if l2[b[i]] + l1[b[i]] > 1:
			cout('YES\n')
			cout('1 ' + str(b[i]) + '\n')
			break
	else:
		cout('NO\n')
