for _ in range(int(input())):
	n = int(input())
	l = list(map(int,input().split()))
	pos,neg=False,False
	if l[0]>0:
		pos = True 
	else:
		neg = True
	li = [l[0]]
	
	for i in range(1,n):
		if l[i]>0:
			if pos:
				li[-1] = max(li[-1],l[i])
			else:
				neg = False
				pos = True 
				li.append(l[i])
		else:
			if neg:
				li[-1] = max(li[-1],l[i])
			else:
				neg = True 
				pos = False 
				li.append(l[i])
	print(sum(li))		
