t=int(input())
for i in range(t):
    maxn=-1000000001
    maxp=0
    sm=0
    c=0
    n=int(input())
    l=list(map(int,input().split()))
    res=l[0]
    if(res>0):
        c=1
        maxp=res
    else:
        c=0
        maxn=res
    if(n==1):
        print(l[0])
    else:
        for j in range(1,n):
            if(l[j]>0 and c==1):
                maxp=max(maxp,l[j])
            elif(l[j]<0 and c==0):
                maxn=max(maxn,l[j])
            elif(l[j]>0 and c==0):
                sm+=maxn
                maxn=-1000000001
                maxp=l[j]
                c=1
            elif(l[j]<0 and c==1):
                sm+=maxp
                maxp=0
                maxn=l[j]
                c=0
        if(maxp==0 and maxn!=-1000000001):
            print(sm+maxn)
        elif(maxn==-1000000001 and maxp!=0):
            print(sm+maxp)
        else:
            print(sm)