a = int(input())

for i in range(0,a):
    b = int(input())
    c = list(map(int,input().split()))
    j = 0
    hello = []
    bye = []
    while j != b-1:
        switch = 0
        if c[j]*c[j+1] < 0 :
            hello.append(c[j])
            switch = 1
        if switch == 0:
            hello.append(c[j])
        if switch == 1:
            if hello[0] > 0:
                bye.append(max(hello))
                hello=[]
                switch = 0
            else:
                bye.append(max(hello))
                hello=[]
                switch = 0
        j+=1
    if len(hello) == 0:
        bye.append(c[b-1])
    else:
        hello.append(c[b-1])
        if hello[0] > 0:
                bye.append(max(hello))
        else:
                bye.append(max(hello))
    print(sum(bye))
                
        
        