# Fall 7, Stand 8...
def main():
    for tin in range(int(input())):
        n=int(input())
        a=list(map(int,input().split()))
        s=a[0];
        if a[0]<0:
            k=-1
        else:
            k=1
        b=[]
        for _ in range(1,n):
            if((k==-1 and a[_]<0) or (k==1 and a[_]>0)):
                if s<a[_]:
                    s=a[_]
            elif (k==-1 and a[_]>0) or (k==1 and a[_]<0):
                b.append(s)
                k*=-1
                s=a[_]
        b.append(s)
        print(sum(b))
main()