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
	res = []
	res.append(a[0])
	for i in range(1, n):
		if sign == 1:
			if a[i] < 0:
				res.append(a[i])
				sign = 0
			else:
				if a[i] > res[-1]:
					res[-1] = a[i]
				
		else:
			if a[i] > 0:
				res.append(a[i])
				sign = 1
			else:
				if a[i] > res[-1]:
					res[-1] = a[i]
					
				
	print(sum(res))

