sign=lambda x: (1, -1)[x < 0]

t=int(input())
for _ in range(t):
    n=int(input())
    a=[int(x) for x in input().split()]
    k=1
    sum=0
    x=a[0]
    maxi=x
    psign=sign(x)
    for i in range(1,n):
        x=a[i]
        if sign(x)!=psign:
            k+=1
            sum+=maxi
            maxi=x
            psign=sign(x)
        else:
            maxi=max(maxi,x)
    sum+=maxi
    print(sum)