# -*- coding: utf-8 -*-
"""
Created on Fri May 22 08:07:12 2020

@author: Harshal
"""

def sgn(i,j):
    if (i>=0 and j>=0) or (i<0 and j<0):
        return True
    else:
        False
test=int(input())
for t in range(test):
    n=int(input())
    nums=list(map(int,input().split()))
    i=0
    ans=0
    while i<n:
        j=i+1
        while j<n and sgn(nums[i],nums[j])==True:
            j+=1
        else:
            ans+=max(nums[i:j])
            i=j
    print(ans)