def sign(x):
    return int(x>0)
t=int(input())
for i in range(t):
    n=int(input())
    a=list(int(num) for num in input().split(" "))[:n]
    i=0
    b=[]
    while i<(n):
        if i==0:
            b.append(a[i])
            i=i+1
        else:
            if sign(a[i-1])==sign(a[i]):
                maxi=max(b[len(b)-1],a[i])
                if maxi==a[i]:
                    b.remove(b[len(b)-1])
                    b.append(a[i])
                    i=i+1
                else:
                    i=i+1
            else:
                b.append(a[i])
                i=i+1
    print(sum(b))
