t=int(input())
for _ in range(t):
    r=[]
    n=int(input())
    l=list(map(int,input().split()))
    p=l[0]
    for x in l:
            if x*p<0:
                r.append(p)
                p=x
            elif x>p:
                p=x
    r.append(p)
    print(sum(r))