x=int(input())
for i in range(x):
    n=int(input())
    arr=list(map(int,raw_input().split()))


    def oppositeSigns(x, y):
        return ((x ^ y) < 0)

    def check(arr,n):
        sum_till=0
        sum_total=0
        a=[]
        for i in range(n-1):
            if oppositeSigns(arr[i],arr[i+1])==True:
                sum_till+=arr[i]
            else:
                sum_till+=arr[i]
                a.append(sum_till)
                sum_till=0
        if len(a)==0:
            return sum(arr)
        else:
            return max(a)
    print check(arr,n)