q = int(input())
for q0 in range(q):
	n = int(input())
	str1 = input()
	list4 = str1.split()
	list1 = [int(o) for o in list4]
	list3 = []
	i = list1[0]
	for w in range(n):
		if i * list1[w] > 0:
			i = max(i,list1[w])
		else:
			list3.append(i)
			i = list1[w]
	list3.append(i)
	print(sum(list3))