t=int(input())
while(t):
    n=int(input())
    a=list(map(int,input().rstrip().split()))
    ans=0
    c=float('-inf')
    T1,T2=False,False
    for i in range(n):
        if a[i]>0:
            T1=True
            if T2:
                ans+=c
                T2=False
                c=a[i]
            c=max(c,a[i])
        else:
            T2=True
            if T1:
                ans+=c
                T1=False
                c=a[i]
            c=max(c,a[i])
    print(ans)
    t-=1