t= int(input())
for i in range(t):
    n=int(input())
    arr= map(int,input().split(' '))
    i=0
    chosen=-1
    summ=0
    pos=False
    for a in arr:
        if i==0:
            pos=a>0
            chosen=a
            i+=1
        else:
            if pos and a<0:
                pos=False
                summ+=chosen
                chosen=a
            elif not pos and a>0:
                pos=True
                summ+=chosen
                chosen=a
            else:
                if a>chosen:
                    chosen=a
    summ+=chosen
    print(summ)