'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''



def main():
	t = int(input())
	while t:
		n = int(input())
		arr = list(map(int,input().split()))
		x = arr[0]
		index,i = 0,0
		ans = 0
		while i<len(arr):
			mac = arr[index]
			# index+=
			while index<len(arr) and (arr[index] ^ x)>=0:
				if mac<arr[index]:
					mac = arr[index]
				x = arr[index]
				index+=1
			ans+=mac
			i = index
			if index==len(arr):
				break
			x = arr[index]
		print(ans)
		t-=1
main()