'''input
4
5
1 2 3 -1 -2
4
-1 -2 -1 -3
10
-2 8 3 8 -4 -15 5 -2 -3 1
6
1 -1000000000 1 -1000000000 1 -1000000000
'''
from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())
import bisect
import math
t = input()
for _ in range(t):
	n = input()
	a = I()
	ans = 0;
	nos = []
	i = 0
	if (a[0] > 0):
		sign = 1;
	else:
		sign = 0;
	temp = []
	while (i < n):
		if (sign):
			if (a[i] > 0):
				temp.append(a[i])
			else:
				nos.append(temp)
				sign = 0
				temp = []
				temp.append(a[i])
		else:
			if (a[i] < 0):
				temp.append(a[i])
			else:
				nos.append(temp)
				sign = 1
				temp = []
				temp.append(a[i])
		i+=1
	nos.append(temp)
	for it in nos:
		ans += max(it)
	print ans 
