for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	curr_max = a[0]
	curr_sign = a[0] > 0
	for i in range(1, len(a)):
		sign = a[i] > 0
		if sign != curr_sign:
			ans += curr_max
			curr_max = a[i]
			curr_sign = sign
		else:
			curr_max = max(curr_max, a[i])
	ans += curr_max
	print(ans)
