tc=int(input())
while(tc>0):
    tc-=1
    n=int(input())
    l=list(map(int,input().split()))
    ans=[]
    i=0
    mx=0
    while(i<n):
        if l[i]<0:
            cnt=l[i]
            while(i<n and l[i]<0):
                if l[i]>cnt:
                    cnt=l[i]
                i+=1
        else:
            cnt=l[i]
            while(i<n and l[i]>0):
                if l[i]>cnt:
                    cnt=l[i]
                i+=1
        mx+=cnt
    print(mx)
            
