t=int(input())
while(t):
    t=t-1
    n=int(input())
    l=list(map(int,input().split()))
    ans=0
    k=-1
    for i in range(n-1):
        if l[i]*l[i+1]<0:
            ans=ans+max(l[k+1:i+1])
            k=i
    if k<n-1:
        ans=ans+max(l[k+1:])
    print(ans)