T = int(raw_input())
for t in range(T):
	raw_input()
	arr = map(int, raw_input().split())
	total = 0
	max_seen = arr[0]	
	for a in arr:		
		if max_seen * a < 0:
			total += max_seen
			max_seen = a
		if max_seen < a:
			max_seen = a

	print total + max_seen


