t=int(input())
def fun(n,a):
    s=0
    i=0
    se=0
    while i<n:
        k=0
        if se==0:
            while i<n and a[i]>0:
                k=max(k,a[i])
                i+=1
            s+=k
            se+=1
        else:
            k=-10**9
            k-=10
            while i<n and a[i]<0:
                k=max(k,a[i])
                i+=1
            s+=k
            se-=1
    print(s)
while t:
    t-=1
    n=int(input())
    a=[int(i) for i in input().split()]
    fun(n,a)


