def solve(ar,n):
    if(ar[0]>0):
        positive=True
    else:
        positive=False
    sum1=ar[0]
    index=0
    for i in range(1,n):
        if(positive and ar[i]>0):
            if(sum1-ar[index]+ar[i]>sum1):
                sum1=sum1-ar[index]+ar[i]
                index=i
        elif(positive and ar[i]<0):
            sum1=sum1+ar[i]
            index=i
            positive=False
        elif(positive!=True and ar[i]<0):
            if(sum1-ar[index]+ar[i]>sum1):
                sum1=sum1-ar[index]+ar[i]
                index=i
        else:
            sum1=sum1+ar[i]
            index=i
            positive=True
    return(sum1)
            
for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    print(solve(l,n))