test=int(input())
for i in range(test):
    n=int(input())
    l=list(map(int,input().split()))
    c,s,t,t1=0,0,0,0
    for i in range(len(l)):
        if(c==2)and(l[i]>0):
            s=s+(t+t1)
            t,t1,c=0,0,0
        if(l[i]>0)and(c==0):
            c+=1
            t=l[i]
        elif(l[i]>0)and(c==1)and(t<l[i]):
            t=l[i]
        elif(l[i]<0)and(c==1):
            t1=l[i]
            c+=1
        elif(l[i]<0)and(c==2)and(t1<l[i]):
            t1=l[i]
    if(t!=0)and(t1!=0):
        s=s+(t+t1)
        print(1)
        t,t1,c=0,0,0
    if(l[n-1]>0)and(l[0]<0):
        s=s+l[n-1]+l[0]
    if(s==0):
        print(max(l))
    else:
        print(s)
            
            
