
for _ in range(int(input())):

    n=int(input())
    l=list(map(int,input().split()))
    t1=[]
    t2=set()

    j=[]
    
    for i in range(1,n):
#        print(l[i],l[i-1])
        if l[i]>0 and l[i-1]<0:
            if len(j)>0:
                j.append(l[i])

            else:
                j.append(l[i])
                j.append(l[i-1])
            
        elif l[i]<0 and l[i-1]>0:
            if len(j)>0:
                j.append(l[i])

            else:
                j.append(l[i])
                j.append(l[i-1])

        else:
            if len(j)>1:
                t1.append(j)
            else:
                t2.add(l[i-1])
                t2.add(l[i])
            
            j=[]
            
    t1.append(j)
    mxx=-pow(10,18)

    if len(t1)>0 and len(t1[0])>0:
        
        for i in range(len(t1)):

            t1[i]=list(t1[i])
            k=sum(t1[i])

            if k>mxx:
                mxx=k

    else:
        t2=list(t2)
        for i in range(len(t2)):
            if t2[i]>mxx:
                mxx=t2[i]

    print(mxx)