t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    c=0
    i=0
    while i<n:
        if a[i]>0:
            m = float('-inf')
            while i<n and a[i]>0:
                m=max(a[i],m)
                i+=1
            c+=m
        elif  a[i]<0:
            m=float('-inf')
            while i<n and  a[i]<0:
                m=max(m,a[i])
                i+=1
            c+=m

    print(c)