for _ in range(int(input())):
    n=int(input())
    a=list(map(int, input().split()))
    a.append(0)
    b=[]
    maxv=a[0]
    for i in range(n):
        maxv= max(maxv, a[i])
        if a[i]>0 and a[i+1] <0: #+ -
            b.append(maxv)
            maxv=-10000000
        elif a[i]<0 and a[i+1]>0: #- +
            b.append(maxv)
            maxv=0        
    b.append(maxv)
    # x= maxSubArraySum(b,len(b))
    print(sum(b))