T =int(input())
for _ in range(T):
    n =int(input())
    arr = [int(x) for x in input().split()]
    if n==1:
        print(0)
    else:
        if arr[0]>=0:
            j=1
        else:
            j=-1
        once = 0
        check=arr[0]
        count=0
        for i in range(1,n):
            print(check,count,j)
            if j==1:
                if arr[i]>check:
                    check = arr[i]
                if arr[i]<0:
                    once=1
                    count+=check
                    check=arr[i]
                    j=-1
            if j==-1:
                if arr[i]>check and arr[i] < 0:
                    check = arr[i]
                if arr[i]>0:
                    once=1
                    count+=check
                    check=arr[i]
                    j=1
            if i==n-1:
                count+=check
        if once ==0:
            print(0)
        else:
            print(count)
        
        
        
            