t=int(input())
for i in range(t):
    length=int(input())
    ar=list(map(int,input().split(' ')))
    p,n,s=0,0,0
    arr=[]
    for k in range(length):
        if(k==0):
            if(ar[k]<0):
                n=ar[k]
            else:
                p=ar[k]
        else:
            if(ar[k]<0 and n<0):
                if(n>ar[k]):
                    continue
                else:
                    n=ar[k]
            elif(ar[k]>0 and n<0):
                arr.append(n)
                n=0
                p=ar[k]
            elif(ar[k]<0 and p>0):
                arr.append(p)
                p=0
                n=ar[k]
            else:
                if(p>ar[k]):
                    continue
                else:
                    p=ar[k]
    if(p>0):
        arr.append(p)
    if(n<0):
        arr.append(n)
    print(sum(arr))

            
