#qn given an arr of size n for every  i position find a min j such that j>i and arr[j]>arr[i]
#it prints the position of the nearest .
import sys
input = sys.stdin.readline
 #qn given an arr of size n for every  i position find a min j such that j>i and arr[j]>arr[i]
#it prints the position of the nearest .
# import sys
import heapq 
import copy
import math
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13

# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
############ ---- Input Functions ---- #######Start#####
def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End#####   
def bin_search(arr,l,r,val):#strickly greater
	if arr[r] <= val:
		return r+1	
	if r-l < 2:
		if arr[l]>val:
			return l
		else:
			return r
	mid = int((l+r)/2)
	if arr[mid] <= val:
		return bin_search(arr,mid,r,val)
	else:
		return bin_search(arr,l,mid,val)

def pr_list(a):
	print(*a, sep=" ")
def main():
	tests =  inp()
	mod = 1000000007
	limit = 10**18
	# print(limit)
	for test in range(tests):
		n =  inp()
		a = inlt()
		dp = [[0 for i in range(2)]for j in range(n)]
		itr_p = -1
		itr_n = -1
		for i in range(n):
			if  a[i] > 0:
				if itr_n == -1:
					dp[i][0] = 1
					dp[i][1] = a[i]
				else:
					dp[i][0] = 1+dp[itr_n][0]
					dp[i][1] =  dp[itr_n][1]+a[i]

				if dp[itr_p][0] == dp[i][0] :
					if a[itr_p] < a[i]:
						itr_p = i
				else:
					itr_p = i
			else:
				if itr_p == -1:
					dp[i][0] = 1
					dp[i][1] = a[i]
				else:
					dp[i][0] = 1+dp[itr_p][0]
					dp[i][1] =  dp[itr_p][1]+a[i]
				if dp[itr_n][0] == dp[i][0] :
					if a[itr_n] < a[i]:
						itr_n = i
				else:
					itr_n = i
		m_size = 0
		m_sum = -1*sys.maxsize
		for i in range(n):
			if dp[i][0] > m_size:
				m_size = dp[i][0]
				m_sum = dp[i][1]
			elif dp[i][0] == m_size:
				m_sum =max(dp[i][1],m_sum)

		# print(m_size)
		# print(dp)
		print(m_sum)






	return 0


# if for two position i,j such that j<i and arr[j]>arr[i] I wont need to store the position i as I wont requre it for any further computation. I cound simply use i instead of j.
#to do that i main tain a stack which is initiallized with the last elment and I traverse the arr backwords because for any ith entry the answer does not depends on 0 to i-1.
# for every element I would continue to pop the stack (from last) till i recieve an elemnt larger than current one. The elemnt which i poped are not needed as i could use current elemnt.
# the order is n as an element only enters the stack ones.
if __name__== "__main__":
  main()