t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    a+=[0]
    if n==1:print(a[0])
    else:
        ans=0
        m=a[0]
        for i in range(n):
            if a[i+1]*a[i]<=0:ans+=m;m=a[i+1]
            else:
                if a[i+1]>m:m=a[i+1]
        print(ans)