for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    if(n==0 or n==1):
        print(sum(a))
    else:
        s=0
        p=0
        ne=-1000000000
        fp=0
        fn=0
        for i in range(n):
            if(a[i]<0):
                if(fn==1):
                    ne=max(ne,a[i])
                else:
                    ne=a[i]
                fn=1
                if(fp==1):
                    s+=p
                fp=0
            else:
                if(fp==1):
                    p=max(p,a[i])
                else:
                    p=a[i]
                fp=1
                if(fn==1):
                    s+=ne
                fn=0
        if(a[n-1]<0):
            s+=ne
        else:
            s+=p
        print(s)