import math
t = int(input())




for i in range(t):

	n = int(input())
	l = list(map(int, input().split()))

	res = [l[0]]
	for i in range(1, len(l)):
		if(abs(res[-1]) + abs(l[i]) == abs(l[i] + res[-1])):

			if(res[-1] < l[i]):
				
				res[-1] = l[i]
				
		else:

			res.append(l[i])
			

	
	print(sum(res))

















		















	
















		


















		













