import sys
input = lambda:sys.stdin.readline()

int_arr = lambda: list(map(int,input().split()))
str_arr = lambda: list(map(str,input().split()))
get_str = lambda: map(str,input().split())
get_int = lambda: map(int,input().split())
get_flo = lambda: map(float,input().split())

mod = 1000000007

def solve(n,arr):
	tot = 0
	i = 0
	check = True
	val = arr[0]
	if val < 0 :
		check = False
	for i in range(n):
		curr = True
		if arr[i] < 0:
			curr = False
		if check == curr:
			val = max(arr[i],val)
		else:
			tot += val
			val = arr[i]
		check = curr
	print(tot+val)





for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	solve(n,arr)
