from sys import stdin

def help():
	stri=stdin.readline().strip("\n")
	n=int(stri)

	arr=list(map(int,stdin.readline().split(" ")))

	if(arr[0]<0):
		sign=0
	else:
		sign=1
	sumi=0

	currmax=arr[0]

	for i in range(1,n):
		if(sign==0 and arr[i]<0):
			currmax=max(arr[i],currmax)
		elif(sign==1 and arr[i]>0):
			currmax=max(arr[i],currmax)
		else:
			sumi+=currmax
			if(arr[i]<0):
				sign=0
			else:
				sign=1
			currmax=arr[i]
	sumi+=currmax
	print(sumi)









for i in range(int(stdin.readline())):
	help()


# def help(ii):
# 	# stri=stdin.readline().strip("\n")
	
# #	row,col,r1,c1,r2,c2=map(int,stdin.readline().split(" "))

# 	arr=[[0]*row for i in range(col)]



# #	print("Case #"+str(ii+1)+":",east,south)



# for i in range(int(stdin.readline())):
# 	help(i)

# row,col=map(int,stdin.readline().split(" "))

# def func(row,col):
# 	arr=[[0]*(col) for i in range(row)]

# 	arr[0][0]=1

# 	for i in range(row):
# 		for j in range(col):
# 			if(i+1==row and j+1==col):
# 				continue
# 			elif(i+1==row):
# 				arr[i][j+1]+=arr[i][j]
# 			elif(j+1==col):
# 				arr[i+1][j]+=arr[i][j]
# 			else:
# 				arr[i+1][j]+=arr[i][j]/2
# 				arr[i][j+1]+=arr[i][j]/2

# 	for i in range(row):
# 		print(*arr[i],sep="\t\t")

# func(8,8)