t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	flag = 1 if arr[0] >= 0 else 0
	if flag == 1:
		mp = arr[0]
		mn = -99999999999
	else:
		mp = -99999999999
		mn = arr[0]
	s = 0
	for i in range(1, n):
		if flag == 1:
			mn = -99999999999
			if arr[i] < 0:
				s += mp
				mn = arr[i]
				flag = 0
			else:
				mp = max(arr[i], mp)
		elif flag == 0:
			mp = -99999999999
			if arr[i] >= 0:
				s += mn
				mp = arr[i]
				flag = 1
			else:
				mn = max(arr[i], mn)

	if flag == 1:
		print(s + mp)
	else:
		print(s + mn)


