for _ in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))

	i = 0
	res = 0
	
	if(arr[0] >= 0):
		m = arr[0]
		i = 0
		while i<N and arr[i]>=0:
			if arr[i] > m: m = arr[i]
			i += 1
		res += m
	
	while i<N:
		m = arr[i]
		while i<N and arr[i]<0:
			if arr[i] > m: m = arr[i]
			i += 1
		res += m
		if i>=N: break
		m = arr[i]
		while i<N and arr[i]>=0:
			if arr[i] > m: m = arr[i]
			i += 1
		res += m

	print(res)