from sys import stdin
def input():
    return stdin.readline()
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    if(n==0 or n==1):
        print(sum(a))
        continue
    else:
        su=0
        pos=0
        neg=-1000000000
        fp=0
        fn=0
        for i in range(n):
            if(a[i]<0):
                if(fn==1):
                    neg=max(neg,a[i])
                else:
                    neg=a[i]
                fn=1
                if(fp==1):
                    su+=pos
                fp=0
            elif(a[i]>0):
                if(fp==1):
                    pos=max(pos,a[i])
                else:
                    pos=a[i]
                fp=1
                if(fn==1):
                    su+=neg
                fn=0
        if(a[n-1]<0):
            su+=neg
        else:
            su+=pos
        print(su)