num = int(input())
for _ in range(num):
	n = int(input())
	list_ = [int(i) for i in input().split()]

	tmp = None
	count = 0
	for i in list_:
		if not tmp:
			tmp = 1 if i > 0 else -1
			count += 1
		if (i ^ tmp) < 0:
			count += 1
			tmp = 1 if tmp == -1 else -1
			flag = True

	tmp = list_[0]
	sum_ = 0
	count_2 = 0
	for i in list_:
		if i == tmp:
			continue
		if (tmp ^ i) < 0:
			#print('{} xor {}={}'.format(tmp, i, tmp ^ i))
			sum_ += tmp
			#print('tmp:', tmp)
			tmp = i
			count_2 += 1
			continue
		if i > 0 and i > tmp:
			tmp = i
		elif i < 0 and i > tmp:
			tmp = i
	#print(count, count_2, sum_, tmp)
	if count_2 == count - 1:
		sum_ += tmp

	print(sum_)