def arr_from(minus, a):
	pos1 = []
	i = 0
	minim = None
	maxim = None
	while i < len(a):
		if minus == True:
			if a[i] < 0:
				if minim == None:
					minim = a[i]
				else:
					minim = max(minim, a[i])
				i += 1
			else:
				if minim != None:
					minus = False
					pos1.append(minim)
					minim = None
				else:
					i += 1
		else:
			if a[i] > 0:
				if maxim == None:
					maxim = a[i]
				else:
					maxim = max(maxim, a[i])
				i += 1
			else:
				if maxim != None:
					minus = True
					pos1.append(maxim)
					maxim = None
				else:
					i += 1

	if minim != None:
		pos1.append(minim)
	if maxim != None:
		pos1.append(maxim)

	return pos1
def main():
	t = int(input())
	for _ in range(t):
		_ = input()
		a = [int(x) for x in input().split()]

		pos1 = arr_from(True, a)
		pos2 = arr_from(False, a)
		if len(pos1) > len(pos2):
			print(sum(pos1))
		else:
			print(sum(pos2))


main()