t = int(input())

def sameSign(a,b):
	if (a>0 and b>0) or (b<0 and a<0):
		return True
	return False
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	
	mx = arr[0]
	prev,ans = arr[0], 0
	
	for i in range(n):
		if sameSign(prev, arr[i]):
			mx = max(mx, arr[i])
		else:
			ans += mx
			mx = arr[i]
		prev = arr[i]
	print(ans + mx)