for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=[]
    for i in range(n):
        if(i<n-1):
            if(a[i]*a[i+1]<0):
                b.append(a[i])
            else:
                if(a[i]>a[i+1]):
                    a[i],a[i+1]=a[i+1],a[i]
        else:
            b.append(a[i])
    print(sum(b))            