def hello():
    n = int(input())
    pos = list(map(int, input().split()))
    mas_s = 1
    maxim = pos[0]
    v = []
    s = 0
    for i in range(1, n):
        if pos[i] * pos[i - 1] < 0:
            s += maxim
            maxim = pos[i]
        else:
            maxim = max(maxim, pos[i])
    s += maxim
    print(s)



    '''if pos[i] * pos[i - 1] < 0:
            maxim += 1
            v.append(g)
            g = [pos[i]]
        else:
            g.append(pos[i])
    print(v)
    print(maxim)'''

    for i in range(n):
        pass



a = int(input())
for i in range(a):
    hello()

