from sys import stdin, stdout  
  
def main(): 
	N = int(stdin.readline()) 
	for tc in range(N):
		n = int(stdin.readline())
		arr = [int(x) for x in stdin.readline().split()]
		minn = float('-inf')
		neg = None
		if arr[0] < 0:
			neg = True
		else: 
			neg = False
		res = 0 
		for x in arr:
			if x < 0 and neg == False or  x > 0 and neg == True:
				res += minn
				minn = float('-inf')
				if x < 0:
					neg = True
				else: 
					neg = False
			if x > minn: 
				minn = x
			# print(minn,minn)
		stdout.write(str(res + minn)+'\n')
if __name__ == "__main__": 
	main()