'''
def Sort_Tuple(tup):
    tup.sort(key = lambda x: x[1])  
    return tup  
'''
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    i=0
    sum=0
    while(i<len(a)):
        if a[i]<0:
            ans=[]
            while(i<len(a) and a[i]<0):
                ans.append(a[i])
                i+=1
            sum+=max(ans)
        else:
            ans=[]
            while(i<len(a) and a[i]>0):
                ans.append(a[i])
                i+=1
            sum+=max(ans)
    print(sum)