import sys
tt = int(input())

while tt:
    n = int(input())
    A = [int(x) for x in input().split()]
    sum = 0
    neg = []
    pos = []
    loc_min = -sys.maxsize
    flag = True
    for x in A:
        if x<0:
            flag = False
            if x>loc_min:
                loc_min = x
        if x>0 and flag == False:
            flag = True
            neg.append(loc_min)
            loc_min = -sys.maxsize
    if A[n-1]<0:
        neg.append(loc_min)

    loc_max = 0
    flag = True
    for x in A:
        if x > 0:
            if x > loc_max:
                flag = False
                loc_max = x
        if x < 0 and flag == False:
            pos.append(loc_max)
            loc_max = 0
            flag = True
    if A[n-1]>0:
        pos.append(loc_max)
    size = min(len(pos),len(neg))
    #print(pos)
    #print(neg)
    for i in range(0,size):
        sum += pos[i]+neg[i]
    if size == 0:
        sum = max(A)
    print(sum)
    tt -= 1
