t=int(input())
for q in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    last=0
    s=0
    for x in range(n):
        if x!=0 and x!=n-1:
            if a[x]<0:
                if last<0:
                    if a[x]>last:
                        last=a[x]
                else:
                    s+=last
                    last=a[x]
            else:
                if last>0:
                    if a[x]>last:
                        last=a[x]
                else:
                    s+=last
                    last=a[x]
        elif x==n-1:
            if a[x]<0:
                if last<0:
                    if a[x]>last:
                        last=a[x]
                        s+=last
                    else:
                        s+=last
                else:
                    s+=last
                    s+=a[x]
            else:
                if last>0:
                    if a[x]>last:
                        last=a[x]
                        s+=last
                else:
                    s+=last
                    s+=a[x]

        else:
            last=a[x]      
    print(s)