for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    ans=a[0]
    if(a[0]>0):
        prev=1
        temp=a[0]
    else:
        prev=-1
        temp=a[0]
    for i in range(1,n):
        if((a[i]>0)and(prev==1)):
            if(a[i]>temp):
                ans=ans-temp+a[i]
                temp=a[i]
        elif((a[i]<0)and(prev==-1)):
            if(a[i]>temp):
                ans=ans-temp+a[i]
                temp=a[i]
        else:
            ans+=a[i]
            temp=a[i]
            if(a[i]>0):
                prev=1
            else:
                prev=-1
    print(ans)