from sys import stdin
input=stdin.readline
for _ in range(int(input())):
	n=int(input())
	a=list(map(int,input().split()))
	for i in range(n-1):
		if a[i]>0 and a[i+1]<0 or a[i]<0 and a[i+1]>0:continue
		else:a[i+1]=max(a[i],a[i+1]);a[i]=0
	print(sum(a))		