t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    flag1=0
    flag2=0
    sumk=0
    for i in a:
        if(i>=0):
            if(flag1==0):
                pos=i
                flag1=1
                if(flag2==1):
                    sumk+=neg
            else:
                if(flag3==1 and i>pos):
                    pos=i
                elif(flag3==-1):
                    sumk+=neg
                    pos=i
            flag3=1
        else:
            if(flag2==0):
                neg=i
                flag2=1
                if(flag1==1):
                    sumk+=pos
            else:
                if(flag3==-1 and i>neg):
                    neg=i
                elif(flag3==1):
                    sumk+=pos
                    neg=i
            flag3=-1
    if(flag3==-1):
        sumk+=neg
    elif(flag3==1):
        sumk+=pos
    print(sumk)
           
           
