def main():
	for _ in range(int(input())):
		sizea, sizeb = map(int, input().split())
		a = [int(i) for i in input().split()]
		b = [int(i) for i in input().split()]
		c = set(a)&set(b)
		if c:
			print("YES")
			print(1, c.pop())
		else:
			print("NO")


main()