if __name__ == "__main__":
	t = int(input())
	for test in range(t):
		n, m = input().split()
		a = set(input().split())
		b = set(input().split())
		flag = False
		value = 0
		for i in a:
			if i in b:
				flag = True
				value = i
				break
			if flag:
				break
		if flag:
			print("YES")
			print(1, value)
		else:
			print("NO")