import sys
tt = int(input())

while tt:
    n = int(input())
    A = [int(x) for x in input().split()]
    sum = 0

    flag2 = False
    if A[0] <0:
        for x in A:
            if x>0:
                flag2 = True
                break
        if flag2 == False:
            print(max(A))
            tt -= 1
            continue
        i = 0
        while i<n:
            neg = -sys.maxsize
            pos = 0
            flag = False
            while i<n and A[i] < 0:
                if A[i]>neg:
                    neg = A[i]
                i+=1

            while i<n and A[i] > 0:
                flag = True
                if A[i]>pos:
                    pos = A[i]
                i+=1
            if flag == True:
                sum += pos + neg
                #print(sum)
    else:
        for x in A:
            if x<0:
                flag2 = True
                break
        if flag2 == False:
            print(max(A))
            tt -= 1
            continue
        i = 0
        while i < n:
            neg = -sys.maxsize
            pos = 0
            flag = False
            while i<n and A[i] > 0:
                if A[i] > pos:
                    pos = A[i]
                i += 1

            while i<n and A[i] < 0 :
                flag = True
                if A[i] > neg:
                    neg = A[i]
                i += 1
            if flag == True:
                sum += pos + neg

    print(sum)

    tt -= 1
