t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    m=a[0]
    c=0
    ans=0
    for i in range(1,n):
        if (a[i]<0 and a[i-1]>0) or (a[i]>0 and a[i-1]<0):
            c=0
            #print(m)
            ans=ans+m
            m=a[i]
        else:
            c=c+1
            m=max(m,a[i])
    ans=ans+m
    print(ans)
