from sys import maxsize
def Nav(n,l):
    m=maxsize*2+1
    maxn,minn=-m,-m
    sum=0
    i=0
    f=0
    while i<n:
        if l[i]<0:
            f=0
            while l[i]<0 or f==0:
                maxn=max(maxn,l[i])
                i+=1
                f=1
                if i>n-1:
                    break
            sum+=maxn
            #print(maxn)
        else:
            f=0
            while l[i]>0 or f==0:
                minn=max(minn,l[i])
                i+=1
                f=1
                if i>n-1:
                    break
            sum+=minn
            #print(minn)
        maxn,minn=-m,-m
    return sum

for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    print(Nav(n,l))