for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	pos = []
	nev = []
	ans = []
	for i in a:
		if i > 0:
			if nev != []:
				ans.append(max(nev))
				nev = []
			pos.append(i)
		elif i < 0:
			if pos != []:
				ans.append(max(pos))
				pos = []
			nev.append(i)
	
	if nev != []:
		ans.append(max(nev))
		nev = []
	if pos != []:
		ans.append(max(pos))
		pos = []
	print(sum(ans))
