import sys

def bestSubSequence(arr):
	bestSum = 0
	tam = len(arr)
	flgPosi = 0
	ultSigno = 0
	arrAux = []
	for i in range(tam):
		if i == 0:
			if arr[i] > 0:
				ultSigno = 1
			else:
				ultSigno = 0
				
		if arr[i] >= 0:
			flgPosi = 1
		else:
			flgPosi = 0
		
		if (ultSigno == flgPosi) and (i != tam - 1):
			arrAux.append(arr[i])
		elif (ultSigno != flgPosi) and (i != tam - 1):
			bestSum += max(arrAux)
			arrAux = []
			arrAux.append(arr[i])
		elif (ultSigno == flgPosi) and (i == tam - 1):
			arrAux.append(arr[i])
			bestSum += max(arrAux)
		else:
			bestSum += max(arrAux)
			bestSum += arr[i]
			
		ultSigno = flgPosi
	
	return bestSum

if __name__ == "__main__":
	t = int(sys.stdin.readline())

	for i in range(t):
		l = []
		n = int(sys.stdin.readline())
		a = sys.stdin.readline().split()
		for j in range(n):
			b = int(a[j])
			l.append(b)
		print(bestSubSequence(l))


