def solve():
	n, m = map(int, input().split())
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))

	for number in a:
		if number in b:
			print('YES')
			print(1, number)
			break

	else:
		print('NO')


def main():
	for _ in range(int(input())):
		solve()


if __name__ == '__main__':
	main()