t=int(input())
def max_sum(lista,n):
	i=0
	result=0
	while (i<n):
		maximum1=0
		maximum2=0
		if lista[i]>=0:
			maximum1=lista[i]
			while i<n and lista[i]>=0:
				if lista[i]>maximum1:
					maximum1=lista[i]
				i+=1
		else:
			maximum2=lista[i]
			while i<n and lista[i]<0:
				if lista[i]>maximum2:
					maximum2=lista[i]
				i+=1
		result+=maximum1+maximum2
	return result
for i in range(t):
    n=int(input())
    lista=input().split()
    for j in range(n):
        lista[j]=int(lista[j])
    print(max_sum(lista,n))