t = int(input())
while(t>0):
    t = t-1
    n = int(input())
    a = input()
    A = list(map(int,list(a.split())))
    if min(A)>0:
        print(max(A))
    elif max(A)<0:
        print(max(A))
    else:
        i = 0
        l = []
        while(i<n):
            if A[i]<0:
                j = i+1
                m = A[i]
                while(j<n):
                    if A[j]>0:
                        break
                    else:
                        m = max(m,A[j])
                    j = j+1
                i = j
                l.append(m)
            else:
                j = i+1
                m = A[i]
                while(j<n):
                    if A[j]<0:
                        break
                    else:
                        m = max(m,A[j])
                    j = j+1
                i = j
                l.append(m)
        if len(l)%2 == 0:
            print(sum(l))
        elif len(l) == 1:
            print(sum(l))
        else:
            print(sum(l)-max(l[0],l[-1]))
            
