def Function():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
			print(a[0])
			return
	s = 0
	index = 0
	negOrPos = 0
	start = 0

	if a[0] > a[-1]:
		start = a[index]
		s += start
		if start < 0:
			negOrPos = -1
		else:
			negOrPos = 1
		while index < n-1:
			index += 1
			if negOrPos == 1:
				if a[index] < 0:
					start = a[index]
					s += start
					negOrPos = -1
				
				else:
					if a[index] > start:
						s -= start
						start = a[index]
						s += start

			else:
				if a[index] > 0:
					start = a[index]
					s += start
					negOrPos = 1
				
				else:
					if a[index] > start:
						s -= start
						start = a[index]
						s += start
	else:
		index = n-1
		start = a[index]
		s += start
		if start < 0:
			negOrPos = -1
		else:
			negOrPos = 1
		while index > 0:
			index -= 1
			if negOrPos == 1:
				if a[index] < 0:
					start = a[index]
					s += start
					negOrPos = -1
				
				else:
					if a[index] > start:
						s -= start
						start = a[index]
						s += start

			else:
				if a[index] > 0:
					start = a[index]
					s += start
					negOrPos = 1
				
				else:
					if a[index] > start:
						s -= start
						start = a[index]
						s += start

			
	print(s)




for i in range(int(input())):
	Function()