for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	for i in range(n-1):
		if (l[i]>0 and l[i+1]<0) or (l[i]<0 and l[i+1]>0):
		    continue
		else:
		    l[i+1]=max(l[i],l[i+1]);
		    l[i]=0
	res=0
	for li in l:
	    res+=li
	print(res)