# import math
# from sys import stdin, stdout
# import numpy as np

if __name__ == '__main__':
	for t in range(int(input())):
		n, m = tuple(map(int, input().split()))
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))

		d = {el:True for el in a}
		ispos, elem = False, None

		for el in b:
			if d.get(el, None) is not None:
				ispos = True
				elem = el
				break

		if ispos:
			print("YES")
			print("1", elem)

		else:
			print("NO")