def subseq(n,A):
    count=0
    state=0
    last=A[0]
    if A[0]>0:
        state=1
    for i in range(1,n):
        if state==0:
            if A[i]>0:
                count+=last
                last=A[i]
                state=1
            else:
                if A[i]>last:
                    last=A[i]
        else:
            if A[i]>0:
                if A[i]>last:
                    last=A[i]
            else:
                count+=last
                last=A[i]
                state=0
    return count+last

t=int(input())
for i in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    print(subseq(n,arr))