t = int(input())
for _ in range(t):
    n = int(input())
    l = list(map(int, input().split(" ")))
    
    x = []
    sign = l[0] > 0
    best = l[0]
    for i in l[1:]:
        if(sign == (i > 0)):
            best = max(i, best)
        else:
            x.append(best)
            sign = i > 0
            best = i
    x.append(best)
    
    print(sum(x))
        