t = int(input())
for tt in range(t):
	n = int(input())
	lis = input().split()
	for i in range(n):
		lis[i] = int(lis[i])
	final_answer = []
	best_yet = 0
	for i in range(n):
		if(best_yet==0):
			best_yet = lis[i]
		elif(best_yet>0):
			if(lis[i]>0):
				best_yet = max(best_yet,lis[i])
			else:
				final_answer.append(best_yet)
				best_yet = lis[i]
		else:
			if(lis[i]<0):
				best_yet = max(best_yet,lis[i])
			else:
				final_answer.append(best_yet)
				best_yet = lis[i]
	final_answer.append(best_yet)
	print(sum(final_answer))