t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(x) for x in input().split()]
    x = a[0]
    i = 0
    b = []
    b.append(a[0])
    y = a[0]
    for i in  range(1,n):
        if x > 0 and a[i]< 0 :
            x = a[i]
            y = a[i]
            b.append(a[i])
        elif x < 0 and a[i] > 0 :
            x = a[i]
            b.append(a[i])
        elif x > 0 and a[i] >0:
            if  a[i] > x :
                b.remove(x)
                b.append(a[i])
                x = a[i]
        elif x < 0 and a[i] < 0 :
            if a[i] > y :
                b.remove(y)
                b.append(a[i])
                y = a[i]
        
    print(sum(b))

    

