##=====================================================
from sys import stdin, stdout
from collections import defaultdict, Counter
from functools import lru_cache
from math import gcd,floor,ceil

def ilist():
    return [int(x) for x in stdin.readline().strip().split(" ")]
def iint():
    return int(stdin.readline().strip())
def istr():
    return stdin.readline().strip()
##=====================================================

t=iint()
        
for _x in range(t):
    n=iint()
    arr=ilist()
    posMax=0
    negMax=-float('inf')
    if arr[0]<0:
        pos=False
    else:
        pos=True
        
    i,n=0,len(arr)
    res=[]
    
    while i<n:
        if pos:
            negMax=-float('inf')
            while i<n and arr[i]>0:
                posMax=max(posMax,arr[i])
                i+=1
            pos=False
            res.append(posMax)
        else:
            posMax=0
            while i<n and arr[i]<0:
                negMax=max(negMax,arr[i])
                i+=1
            res.append(negMax)
            pos=True
    print(sum(res))


                
    
    
