T = int(input())

for xx in range(T):
	n = int(input())
	a = list(map(int,input().split()))
	l = [a[0]]
	sim = 0
	if a[0] > 0: flag = 0
	else: flag = 1
	for i in range(1,n):
		if a[i] > 0:
			if flag == 1:
				sim += max(l)
				l = []
				flag = 0
			l.append(a[i])
		elif a[i] < 0:
			if flag == 0:
				sim += max(l)
				l = []
				flag = 1
			l.append(a[i])
	sim += max(l)
	print(sim)