import sys
import math
from  collections import defaultdict

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')


def solve(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = 0
	rec_min = sys.maxsize
	rec_max = -1
	for i in range(n):
		if a[i] < 0:
			if rec_max > 0:
				ans += rec_max
				rec_max = -1
			rec_min = -min(abs(rec_min), abs(a[i]))
		else:
			if rec_min < 0:
				ans += rec_min
				rec_min = sys.maxsize
			rec_max = max(rec_max, a[i])

	if rec_max > 0:
		ans += rec_max

	if rec_min < 0:
		ans += rec_min

	print(ans)




if __name__ == "__main__":
	test_cases = int(input())
	for t in range(1, test_cases + 1):
		solve(t)
