t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int,input().split()))
	ppos,npos,ans = -1,-1,0
	for i in range(n):
		if arr[i]>0 and ppos == -1:
			ppos = i
		if arr[i]<0 and npos == -1:
			npos = i
		if ppos != -1 and npos != -1:
			ans += max(arr[min(npos,ppos):max(npos,ppos)])
			if ppos < npos:
				ppos = -1
			else:
				npos = -1
	ans += max(arr[max(npos,ppos):])
	print(ans)
