import math
num_case = int(input())
for i in range(num_case):
    datain1 = input().split(" ")
    datain = []
    for e in datain1:
        datain.append(int(e))
    sum1 = 0
    i = 0
    max_po = 0
    max_ne = -999999999999999
    while i<len(datain):
        if datain[i]>0:
            j = i
            while datain[j]>0 and j<len(datain)-1:
                if datain[j]>max_po:
                    max_po = datain[j]
                j+=1
            if j==len(datain)-1:
                if datain[j]<0:
                    sum1+=datain[j]
                else:
                    if max_po<datain[j]:
                        sum1+=datain[j]
                    else:
                        sum1+=max_po
                i=j
                i+=1
            else:
                i = j
                sum1+=max_po
                max_po = 0
        else:
            j = i
            while datain[j]<0 and j<len(datain)-1:
                if datain[j]>max_ne:
                    max_ne = datain[j]
                j+=1
            if j==len(datain)-1:
                print(max_ne)
                if datain[j]>0:
                    sum1+=datain[j]
                else:
                    if max_ne<datain[j]:
                        sum1+=datain[j]
                    else:
                        sum1+=max_ne
                i=j
                i+=1
            else:
                print(max_ne)
                i = j
                sum1+=max_ne
                max_ne = -999999999999999
    print(sum1)