def solve(n,d):
    last = 1
    if d[0] < 0:
        last = -1
    sums = 0
    # ans = -4444444
    lastadded = None
    for i in range(n):
        c = d[i]        
        if c * last > 0:
            sums += c
            last *= -1
            lastadded = c
        else:
            if lastadded != None:
                newSum = max(sums,sums + c - lastadded)
                if newSum > sums:
                    sums = newSum    
                    lastadded = c

        #print("i",i,"c",c,"ladded",lastadded,"sum",sums,"last",last)
    return sums


  
def main():
    t = int(input())
    for i in range(t):
        n = int(input())
        d = input()
        d = [int(i) for i in d.split()]
        # a = d[0]
        # b = d[1]
        # c = d[2]
        ans = solve(n,d) 
        print(ans)       
main()