for _ in range(int(input())):
	x = int(input())
	li = list(map(int, input().split()))
	max1, ans = 0, 0
	for i in li:
		if i>=1:
			max1 = max(max1, i)
		else:
			ans += max1
			max1 = 0	
	if li[-1] > 0:
		ans += max1
	max1 = -9*10**9
	for i in li:
		if i <= -1:
			max1 = max(max1, i)
		elif max1 !=  -9*10**9:
			ans += max1
			max1 = -9*10**9
	if li[-1] <0 and max1 != -9*10**9:
		ans += max1
	print(ans)