import sys
input = sys.stdin.readline
for q in range(int(input())):
	n = int(input())
	a = list(map(int,input().split()))
	if a[0] > 0:
		sign = 1
	else:
		sign = 0

	Len = 1
	su = a[0]
	for i in range(1, n):
		if sign == 1:
			if a[i] < 0:
				Len+=1
				su+= a[i]
				sign = 0
			else:
				if Len == 1:
					su = max(su, a[i])
				else:
					pass
		else:
			if a[i] > 0:
				Len+=1
				su+= a[i]
				sign = 1
			else:
				if Len == 1:
					su = max(su, a[i])
				else:
					pass
	print(su)

